0

我有这个<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是否可以将红宝石代码和文本/字符串的混合传递给水豚?

4

2 回答 2

1

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

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

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

于 2013-04-30T11:34:15.210 回答
0

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

should have_selector "#post_example", :text => "For example, type <strong>#{post.title}</strong>"
于 2013-04-30T11:42:31.413 回答