Giter Site home page Giter Site logo

chihsiang / plugin_test_helper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pluginaweek/plugin_test_helper

0.0 2.0 0.0 229 KB

Simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application

Home Page: http://www.pluginaweek.org

License: MIT License

Ruby 99.76% HTML 0.24%

plugin_test_helper's Introduction

plugin_test_helper

plugin_test_helper simplifies plugin testing by creating an isolated Rails environment that simulates its usage in a real application.

Resources

API

Bugs

Development

Testing

Source

  • git://github.com/pluginaweek/plugin_test_helper.git

Mailing List

Description

Plugins often need to initialize a full Rails environment, whether it be for accessing a database or simulating controller access. Traditionally, this has been done by just loading the application that the plugin was added to. However, this can cause all sorts of environment variables to change, making it seem as though the plugin is having problems when it may be something else. It also means that the plugin cannot be tested individually.

plugin_test_helper helps solve this problem by allowing plugins to create their own basic Rails environment with the ability to override any part of it, be it the database configuration, environment configuration, or adding models, controllers, helpers, etc. The following testing structure is assumed:

your_plugin/
your_plugin/test
your_plugin/test/app_root
your_plugin/test/app_root/app
your_plugin/test/app_root/config
your_plugin/test/app_root/db
etc.

The app_root directory is just like your run-of-the-mill Rails application. It can contain the same directories as your full application.

To help generate the various parts of your test application, the following generators are available:

  • plugin_test_helper

  • plugin_test_structure

  • plugin_test_model

  • plugin_test_controller

  • plugin_test_migration

NOTE that you DO NOT need to generate the entire application structure. All that is required is that your test helper load plugin_test_helper. If you do not define a part of the test application (such as the environment configurations or the database configuration), then it will use the existing implementation in plugin_test_helper/generators/plugin_test_structure/templates. However, you can override any of these files by simply defining them in your plugin, using the same directory structure.

Usage

plugin_test_helper

Generates a test helper file that should be required by all unit/functional/integration tests in your plugin.

Example:

$ ruby script/generate plugin_test_helper acts_as_most_popular
      create  vendor/plugins/acts_as_most_popular/test/test_helper.rb
Loaded suite script/generate
Started

Finished in 0.000439 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

plugin_test_structure

Generates the entire test application structure. If you keep all files within your plugin, then you will not need to depend on the plugin_test_helper plugin when testing it.

Example:

$ ruby script/generate plugin_test_structure acts_as_most_popular
      create  vendor/plugins/acts_as_most_popular/test/app_root
      create  vendor/plugins/acts_as_most_popular/test/app_root/config
      create  vendor/plugins/acts_as_most_popular/test/app_root/app
      create  vendor/plugins/acts_as_most_popular/test/app_root/lib
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environments
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/routes.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/boot.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environment.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/database.yml
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environments/sqlite.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environments/sqlite3.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environments/mysql.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environments/in_memory.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/config/environments/postgresql.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/controllers
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/application_controller.rb
Loaded suite script/generate
Started

Finished in 0.000548 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

plugin_test_model

Generates a model within your plugin’s test application. This uses a similar syntax to that of the Rails model generator.

Example:

$ ruby script/generate plugin_test_model acts_as_most_popular Person
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/models/
      create  vendor/plugins/acts_as_most_popular/test/app_root/test/fixtures/
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/models/person.rb
      create  vendor/plugins/acts_as_most_popular/test/app_root/test/fixtures/people.yml
      create  vendor/plugins/acts_as_most_popular/test/app_root/db/migrate
      create  vendor/plugins/acts_as_most_popular/test/app_root/db/migrate/001_create_people.rb
Loaded suite script/generate
Started

Finished in 0.000435 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

plugin_test_controller

Generates a controller within your plugin’s test application. This uses a similar syntax to that of the Rails controller generator.

Example:

$ ruby script/generate plugin_test_controller acts_as_most_popular Person
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/views/person
      create  vendor/plugins/acts_as_most_popular/test/app_root/app/controllers/person_controller.rb
Loaded suite script/generate
Started

Finished in 0.000432 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

plugin_test_migration

Generates a migration within your plugin’s test application. This uses a similar syntax to that of the Rails migration generator.

Example:

$ ruby script/generate plugin_test_migration acts_as_most_popular CreatePeople
      create  vendor/plugins/acts_as_most_popular/test/app_root/db/migrate
      create  vendor/plugins/acts_as_most_popular/test/app_root/db/migrate/001_create_people.rb
Loaded suite script/generate
Started

Finished in 0.000443 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

plugin_test_console

Generates a script for running an interactive console with your plugin’s test application.

Example:

$ ruby script/generate plugin_test_console acts_as_most_popular
      create  vendor/plugins/acts_as_most_popular/test/app_root/../../script
      create  vendor/plugins/acts_as_most_popular/test/app_root/../../script/console
Loaded suite script/generate
Started

Finished in 0.000267 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

Dependencies

Rails 2.3 or later

References

plugin_test_helper's People

Contributors

obrie avatar jinzhu avatar

Watchers

James Cloos avatar Auli.Chan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.