红宝石代码+字符串与水豚文本

时间:2013-04-30 10:52:28

标签: ruby-on-rails ruby ruby-on-rails-3 rspec capybara

我的标记<p>包含下一个内容:

<p id="post_example"> <%= t (".for_example_type") %> <strong><%= post.title %></strong></p>

在我的集成测试中:

it "should have example post" do
  should have_selector "#post_example", :text => "For example, type #{post.title}"
end

1) Index page should have example post
     Failure/Error: should have_selector "#post_example", :text => "For example, type #{post.title}"
       expected #has_selector?("#post_example", {:text=>"For example, type Post number 10"}) to return true, got false
     # ./spec/requests/posts_spec.rb:26:in `block (3 levels) in <top (required)>'

Finished in 3.8 seconds
6 examples, 1 failure

Failed examples:

rspec ./spec/requests/posts_spec.rb:25 # Index page should have example post


Randomized with seed 5480

是否可以传递给水豚:text混合使用红宝石代码和文字/字符串?

2 个答案:

答案 0 :(得分:1)

已经是这样了。查看堆栈跟踪:

expected #has_selector?("#post_example", {:text=>"For example, type Post number 10"})

文字已被解释为::text=>"For example, type Post number 10"

答案 1 :(得分:0)

您应该尝试匹配以下文字:

should have_selector "#post_example", :text => "For example, type <strong>#{post.title}</strong>"