Rspec 如何在渲染视图上测试文本?
这是我的测试:Rspec 如何在渲染视图上测试文本?,rspec,ruby-on-rails-3.2,rspec2,Rspec,Ruby On Rails 3.2,Rspec2,这是我的测试: require "rspec" describe HomeController do render_views it "should renders the home" do get :home response.should render_template("home") response.should include_text("Simulate Circuits Online") end end 但是,我得到了: 1) HomeC
require "rspec"
describe HomeController do
render_views
it "should renders the home" do
get :home
response.should render_template("home")
response.should include_text("Simulate Circuits Online")
end
end
但是,我得到了:
1) HomeController should renders the home
Failure/Error: response.should include_text("Some text to be test ..")
NoMethodError:
undefined method `include_text' for #<RSpec::Core::ExampleGroup::Nested_1:0xd429a0c>
# ./spec/controllers/home_controller_spec.rb:9:in `block (2 levels) in <top (required)>'
# (eval):6:in `block in fork'
# (eval):6:in `fork'
# (eval):6:in `fork'
试试这个:
response.should have_content("Simulate Circuits Online")
在视图模板中,您是否确实有要检查的文本?错误似乎是它实际上找不到文本
另外,尝试使用
response.should_text
您还可以使用DOM元素的属性和内容
expect(page).to have_selector 'h1', :text => 'Your text here'
此方法无法检索任何弃用警告。我搜索了RSpec的文本匹配程序,但是,我找不到任何文本匹配程序,您能告诉我在哪里阅读吗?
expect(page).to have_selector 'h1', :text => 'Your text here'