I have been using webrat with my rails 3.0.7 project and have been trying to write a test that uses regular expressions. It should fail, yet the if statement seems to corrupt the outcome.
it "should have 'microposts' if 0 posted" do
visit root_path
response.should have_selector('span.microposts') do |span|
开发者_如何学JAVA if span =~ /\d/
span.should contain('hello')
end
end
end
The test is trying to confirm that the test, yet it still succeeds when an 'if' statement is used. It is trying to match the content '0 microposts'.
When I use these lines in replacement of the 'if' statement:
response.should have_selector('span.microposts') do |counter|
counter.should contain(/hello/)
end
I get the test to finally fail like it is supposed to, but then I don't get to verify the number in front of the content inside of the span like I was trying to above.
Does webrat not hand if statements well, or am I doing something wrong?
Thanks in advance!
It seems you are missing an end
but I don't see how that wouldn't bomb.
it "should have 'microposts' if 0 posted" do
visit root_path
response.should have_selector('span.microposts') do |span|
if span =~ /\d/
span.should contain('hello')
end
end
end
精彩评论