我写了一个非常基本的RSpec / Capybara Rails测试,但我继续得到那个期望方法未定义
我的规范/功能/ signin_spec.rb:
require "rails_helper"
RSpec.feature "the signin process", :type => :feature do
before :each do
User.create(:email => "user@example.com", :password => "password")
end
scenario "signs me in" do
visit "/users/sign_in"
within("#new_user") do
fill_in "Email", :with => "user@example.com"
fill_in "Password", :with => "password"
end
click_button "Log in"
expect(page).to have_content "successfully"
end
end
rails_helper:
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
spec_helper:
require 'capybara/rspec'
RSpec.configure do |config|
config.include Capybara::DSL
config.expect_with(:rspec) { |c| c.syntax = :should }
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
=begin
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!
if config.files_to_run.one?
config.default_formatter = 'doc'
end
config.profile_examples = 10
config.order = :random
Kernel.srand config.seed
=end
end
答案 0 :(得分:11)
在:expect
中向spec_helper
添加config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
删除了错误
{{1}}
https://www.relishapp.com/rspec/rspec-expectations/docs/syntax-configuration#disable-expect-syntax
感谢您的帮助@apneadiving和Frederick
答案 1 :(得分:0)
只需替换
expectations.syntax = :should
与
expectations.syntax = [:should , :expect]
在您的spec_helper.rb
中答案 2 :(得分:0)
只需替换
expectations.syntax = :should
与
expectations.syntax = [:should , :expect]
在您的spec_helper.rb
中