Bla*_*man 53 rspec ruby-on-rails jruby
我的java web应用程序在tomcat上运行,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
我明白了:
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中包含了水豚吗?
如何知道访问正确的网址?如果我的网址是localhost:3030或localhost:8080怎么办?
我的gemfile:
source 'http://rubygems.org'
gem "activerecord"
gem "rspec"
gem "capybara"
gem "activerecord-jdbcmysql-adapter"
我的spec_helper:
require 'capybara/rspec'
Erd*_*zer 135
关于rspec问题(https://github.com/rspec/rspec-rails/issues/360)
你应该把
config.include Capybara::DSL
在spec_helper.rb中,在配置块内.
小智 9
还要确保您的测试位于/ spec/features目录中.根据rspec-rails和capybara 2.0,在RSpec请求规范中默认不提供Capybara v2及更高版本.他们建议"......将任何使用水豚的测试从规格/要求转移到规格/功能."
默认情况下,如果文件位于spec/requests,spec/integration或示例组中,则会自动包含capybara DSL :type => :request.
因为您的文件在spec/home中,所以不包括capybara助手.你可以遵循上面的模式之一,或者添加include Capybara::DSL也应该做的伎俩(你可能还需要复制一些before(:each)将要设置的东西.)