'shoulda-matchers' gem is not loading when running rspec tests.
Error: NoMethodError: undefined method 'allow_value' for #<RSpec::ExampleGroups::Contact::ActiveModelValidationss:0x007fef1021b310>
versions being used: Ruby 2.2.2
Rails 4.2.1
shoulda-matchers 3.1.1
Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.1'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
gem 'shoulda-matchers', '~> 3.1'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'rubocop', require: false
end
rails_helper.rb:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :active_record
with.library :rails
end
end
end
spec_helper.rb:
RSpec.configure do |config|
require 'factory_girl_rails'
require 'shoulda/matchers'
config.include FactoryGirl::Syntax::Methods
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
end
contact_spec.rb:
require 'spec_helper'
describe Contact do
FactoryGirl.define do
factory :contact do
first_name "Alice"
last_name "Bob"
email_address "alicebob@example.com"
phone_number "555-555-5555"
company_name "ExampleCompany"
end
end
it "has a valid factory" do
expect(build(:contact)).to be_valid
end
describe "ActiveModel validations" do
it { expect(:contact).to allow_value("alice_bob@example.com").for(:email_address) }
end
end
Sorry for all the code. Please note I am using shoulda-matchers version 3.1.1 and adding 'require: false` to the gemfile is no longer needed as noted here http://ift.tt/1KKrQGf
I have also tried adding shoulda-matchers to its own test environment in the Gemfile as below but found no change
group :test do
gem 'shoulda-matchers', '~> 3.1'
end
I've looked online and have found similar problems with solutions that don't work in my case. Any help or advice would be great!
Aucun commentaire:
Enregistrer un commentaire