加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

rspec – 如何在渲染视图上测试文本?

发布时间:2020-12-17 03:22:40 所属栏目:百科 来源:网络整理
导读:这是我的测试: 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") endend 但是,我得到了: 1) Home
这是我的测试:

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(“我的文字……”)

我明白了

1) HomeController should renders the home
     Failure/Error: response.should have_content("My text ..")
       expected there to be text "My text .." in "#"
     # ./spec/controllers/home_controller_spec.rb:9:in `block (2 levels) in <top (required)>'

解决方法

在您的视图模板中,您确实拥有要检查的文本吗?错误似乎是它实际上找不到文本.

另外,尝试使用response.should have_text.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读