我试图关注tutorial here并且我一直密切关注指示,直到这里我还没有真正的问题。
这是我的测试失败。我是新的,请让我知道您希望看到的其他文件。非常感谢提前。
spec_helper.rb
require 'capybara'
RSpec.configure do |config|
config.include Capybara::DSL
end
static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
end
end
测试输出
MantisPowerBook:sample_app mantis$ bundle exec rspec spec/requests/static_pages_spec.rb
F
Failures:
1) Static pages Home page should have the content 'Sample App'
Failure/Error: visit '/static_pages/home'
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007f9e54301228>
# ./spec/requests/static_pages_spec.rb:5:in `block (3 levels) in <top (required)>'
Finished in 0.0005 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:4 # Static pages Home page should have the content 'Sample App'
答案 0 :(得分:1)
将spec_helper.rb文件更改为
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.include Capybara::DSL
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
end
之后,您的规范将因正确的原因而失败
据我所知,错误是因为你有
config.include(水豚:: DSL)
而不是
config.include Capybara :: DSL