在我的 rspec 中找不到访问方法 [英] Visit method not found in my rspec

查看:24
本文介绍了在我的 rspec 中找不到访问方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 java web 应用程序在 tomcat 上运行,地址为 http://localhost:8080/

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

Writing my first spec, 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

我明白了:

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 怎么办?

How will it know to visit the correct url? what if my url is localhost:3030 or localhost:8080?

我的宝石文件:

source 'http://rubygems.org'

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

我的规范助手:

require 'capybara/rspec'

推荐答案

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

Regarding to rspec issues (https://github.com/rspec/rspec-rails/issues/360)

你应该把

config.include Capybara::DSL

spec_helper.rb 中,在配置块内.

in spec_helper.rb, inside the config block.

这篇关于在我的 rspec 中找不到访问方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆