Ruby on rails ruby代码+;带水豚文本的字符串
我有一个带有下一个内容的标签:Ruby on rails ruby代码+;带水豚文本的字符串,ruby-on-rails,ruby,ruby-on-rails-3,rspec,capybara,Ruby On Rails,Ruby,Ruby On Rails 3,Rspec,Capybara,我有一个带有下一个内容的标签: <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 exa
<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
它“应该有示例帖子”吗
应该有#选择器“#post_example”,:text=>“例如,键入#{post.title}”
结束
1) 索引页应该有示例文章
失败/错误:应具有#选择器“#post_example”,:text=>“例如,键入#{post.title}”
期望#has_selector?(#post_example“,{:text=>”例如,键入post number 10“})返回true,但得到false
#./spec/requests/posts_spec.rb:26:in'block(3层)in'
在3.8秒内完成
6例,1例失败
失败的示例:
rspec./spec/requests/posts_spec.rb:25#索引页应该有示例post
随机分配种子5480
是否可以将ruby代码和文本/字符串的混合传递给capybara
:text
呢?事实已经如此。查看堆栈跟踪:
expected #has_selector?("#post_example", {:text=>"For example, type Post number 10"})
文本已被解释:
:Text=>“例如,键入Post number 10”
您应该尝试匹配以下文本:
should have_selector "#post_example", :text => "For example, type <strong>#{post.title}</strong>"
应该有_选择器“#post_example”,:text=>“例如,键入#{post.title}”
您是否发布了有效的代码片段?因为,在测试声明中,文本包含#{post.title},但在错误输出中包含#{post.occulation},并带有它“应该有示例post”do应该有#选择器(#post_示例“,{:text=>”例如,键入post number 10“})end
我得到错误预期的#有#选择器?(#post#u示例“,{:text=>例如,键入Post number 10“})返回true,get false 35;./spec/requests/posts_spec.rb:26:in'block(3层)in'
谢谢!