我有一個很基本的RSpec /水豚Rails的測試寫下來,但我不斷收到意想不到的方法是不確定的未定義的方法`希望」爲#<RSpec的:: ExampleGroups :: TheSigninProcess:0x007fddd28a7750>
我的規格/features/signin_spec.rb:
require "rails_helper"
RSpec.feature "the signin process", :type => :feature do
before :each do
User.create(:email => "[email protected]", :password => "password")
end
scenario "signs me in" do
visit "https://stackoverflow.com/users/sign_in"
within("#new_user") do
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "password"
end
click_button "Log in"
expect(page).to have_content "successfully"
end
end
rails_helper:
這個文件複製到投機/當你運行的導軌上產生的RSpec:安裝'
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
什麼是'rails_helper',你沒有spec_helper嗎? – apneadiving 2015-04-03 07:35:04
它包括spec_helper: – user1166419 2015-04-03 07:36:22
您是否已經關閉了對rspec配置中expect語法的支持? (檢查spec_helper.rb/rails_helper.rb) – 2015-04-03 07:38:43