On Ruby on Rails, how to run ONE functional test when another one is breaking?
let's say you added a controller and action (example: story/index
), and want to run a functional test by
rake test:functionals
and then you found that another part of the project your coworker is working on actually broke the test at an earlier place (another controller/action), before your functional test takes place.
In this case, can you run 开发者_开发技巧just one functional test, which is yours?
Wise-Ass Answer
If you coworker breaks the tests, then he should fix the test, or he shouldn't have committed the code to the repo. That is the main principle that we usually have in projects I work on.
Nice Answer
Try this
rake test:functionals TEST=test/functional/xy_test.rb
Or this
running one test without rake but with explicit $-loadpath works too
here "ruby -I directory" specifies the $loadpath. Otherwise you won't load test environment and "require test_helper" fails!
ruby -I test test/functional/xy_test.rb
1) Perhaps: rake test:units
2) This link might also help you out:
http://rake.rubyforge.org/
3) This might also help you out:
"Typical Rails tests come in the follow forms:
Unit (Model) These test business logic in your models. A well-written Rails application should have the bulk of its code in its models, so the bulk of your tests should be these.
Functional (Controller) These test individual controller actions in isolation.
Integration (Controller to Controller) These test state mutations between/over multiple actions and routing, i.e. ensuring that things don’t totally explode as a user clicks through a typical work flow.
Fixtures Used to hold example model data used to easily instantiate those models in tests, avoiding the tedious process of manually creating model objects.
Unit/Helpers These test helpers used in views.
In other words, the basic relationships look like this:
Model Unit Test Controller Functional Test View (as part of a) Functional Test Controller to Controller Integration Test"
Found at http://rails-nutshell.labs.oreilly.com/ch09.html
Check out the single_test gem which makes it easy to run specific tests (or groups of tests)
精彩评论