开发者

Webrat has unexpected outcome when 'if' statement is used

开发者 https://www.devze.com 2023-03-14 11:11 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消