在我的 rspec 中找不到访问方法

2024-01-05

我的 java web 应用程序运行在 tomcat 上http://localhost-8080.com/ http://localhost:8080/

编写我的第一个规范,home_spec:

require 'spec_helper'


describe "home" do

    it "should render the home page" do
       visit "/"

       page.should have_content("hello world")
    end

end

并运行:

rspec

I get:

F

Failures:

  1) home should render the home page
     Failure/Error: visit "/"
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x242870b7>
     # ./spec/home/home_spec.rb:7:in `(root)'

Finished in 0.012 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/home/home_spec.rb:6 # home should render the home page

难道这不应该工作吗,因为我已经在spec_helper中包含了水豚?

它如何知道访问正确的网址?如果我的 url 是 localhost:3030 或 localhost:8080 怎么办?

我的宝石文件:

source 'http://rubygems.org'

gem "activerecord"
gem "rspec"
gem "capybara"
gem "activerecord-jdbcmysql-adapter"

我的spec_helper:

require 'capybara/rspec'

关于 rspec 问题(https://github.com/rspec/rspec-rails/issues/360 https://github.com/rspec/rspec-rails/issues/360)

你应该把

config.include Capybara::DSL

in 规范助手.rb,在配置块内。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在我的 rspec 中找不到访问方法 的相关文章

随机推荐