This should be simple but I can't find any examples. I have standard functional tests in my rails 3 applicatio开发者_运维技巧n (descending from ActionController::TestCase) that look like:
test "see if 1+1=2" do
....
end
and at the top I have a setup method:
setup do
......
end
How do I exclude a method? I.e.
setup :except => "see if 1+1=2" do
...
end
(above doesn't work obv)
Use shoulda and context blocks, that way you can put the tests using the setup in one context, and the tests not using them in another, or outside the other context block.
I'm curious about this too. A workaround without installing and learning any new gems would be to define a private function within your test
test "see if 1+1=2" do
setup_situation_1
...
end
test "see if 1 * 1 = 1" do
setup_situation_1
..
end
test "see if 1/1 = 1" do
# no setup here
...
end
...
private
def setup_situation_1
...
end
This is the DRY-est approach I can think of without installing/learning a new gem--which may be a preferable solution for some people, especially those new to rails. However, I can't find the documentation on this setup/do method--an "except" clause for setup/do would certainly be DRY-er.
精彩评论