Undefined method validate_uniqueness_of error on sinatra app
lucasdavila opened this issue · 1 comments
lucasdavila commented
Hey guys!
I'm testing a sinatra app, I can use the validate_presence_of
matcher without problem, but the validate_uniqueness_of
is failing.
I already tried to:
- Take a look in the issues #203 and #552
- require all needed gems manually.
- put
require: false
on Gemfile, andrequire shoulda/matchers
on the spec_helper. - configure the Gemfile exactly like the Readme file (without the require: false).
None of these attempts worked 😿 Do you have any idea about what could be misconfigured?
Thank you.
Here is my gems versions:
bundle install
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.6.1
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.1
Using builder 3.2.2
Using activemodel 4.2.1
Using arel 6.0.0
Using activerecord 4.2.1
Using backports 3.6.4
Using diff-lcs 1.2.5
Using multi_json 1.11.0
Using pg 0.18.1
Using rack 1.6.0
Using rack-protection 1.5.3
Using rack-test 0.6.3
Using rspec-support 3.2.2
Using rspec-core 3.2.3
Using rspec-expectations 3.2.1
Using rspec-mocks 3.2.1
Using rspec 3.2.0
Using shoulda-matchers 3.0.0.alpha from git://github.com/thoughtbot/shoulda-matchers.git (at master)
Using tilt 1.4.1
Using sinatra 1.4.6
Using sinatra-activerecord 2.0.6
Using sinatra-contrib 1.4.2
Using bundler 1.9.2
Bundle complete!
Here is my Gemfile:
source "https://rubygems.org/"
gem 'sinatra'
gem 'pg'
gem 'activerecord'
gem 'sinatra-activerecord'
gem 'activesupport'
group :test do
gem 'rspec'
gem 'shoulda-matchers', github: 'thoughtbot/shoulda-matchers'
end
group :development do
gem 'rake'
gem 'sinatra-contrib'
end
Here is my spec_helper:
ENV['RACK_ENV'] = 'test'
Bundler.require :default, :test
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :active_record
with.library :active_model
# with.library :action_controller
end
end
RSpec.configure do |config|
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
Here is the complete log:
$ bundle exec rspec
User
should require full_name to be set
should require username to be set
should require email to be set
should require password to be set
example at ./spec/models/user_spec.rb:9 (FAILED - 1)
example at ./spec/models/user_spec.rb:10 (FAILED - 2)
Failures:
1) User
Failure/Error: it { should validate_uniqueness_of(:username) }
NoMethodError:
undefined method `validate_uniqueness_of' for #<RSpec::ExampleGroups::User:0x007fec2b33ad00>
# ./spec/models/user_spec.rb:9:in `block (2 levels) in <top (required)>'
2) User
Failure/Error: it { should validate_uniqueness_of(:email) }
NoMethodError:
undefined method `validate_uniqueness_of' for #<RSpec::ExampleGroups::User:0x007fec2b339ef0>
# ./spec/models/user_spec.rb:10:in `block (2 levels) in <top (required)>'
Finished in 0.09293 seconds (files took 0.67151 seconds to load)
6 examples, 2 failures
Failed examples:
rspec ./spec/models/user_spec.rb:9 # User
rspec ./spec/models/user_spec.rb:10 # User
lucasdavila commented
I'm closing this issue since I submitted it in the wrong repo, I will submit it again on thoughtbot/shoulda-matchers
.