I am using devise for authentication in my rails app and I'm unable to test any model with RSpec. Controller specs work fine, but I'm unable to make model specs work.
I am getting this error:
Failures:
1) Group should create new group
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `env' for nil:NilClass
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/whiny_nil.rb:48:in `method_missing'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.4.2/lib/devise/test_helpers.rb:25:in `setup_controller_for_warden'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-rails-2.5.0/lib/rspec/rails/adapters.rb:11:in `block (2 levels) in setup'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `instance_eval'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:29:in `run_in'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `block in run_all'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:64:in `run_all'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/hooks.rb:110:in `run_hook'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `block in eval_before_eachs'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:144:in `run_before_each'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:48:in `block (2 levels) in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:106:in `with_around_hooks'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:46:in `block in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:99:in `block in with_pending_capture'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `catch'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:98:in `with_pending_capture'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example.rb:45:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:262:in `block in run_examples'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `map'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:258:in `run_examples'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/example_group.rb:232:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block (2 levels) in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `map'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:27:in `block in run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/reporter.rb:12:in `report'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:24:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:55:in `run_in_process'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:46:in `run'
# /home/hrvoje/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:10:in `block in autorun'
I have included
config.include Devise::TestHelpers
in my spec_helper.rb.
Here is my model test file
require 'spec_helper'
describe Group do
before :each do
#group = Factory.build(:group)
end
it "should create new group" do
Group.create!(#group)
end
end
This is my factories.rb file
Factory.define :group do |group|
group.name "Example group"
group.description "Example description"
end
How to fix this?
config.include Devise::TestHelpers, :type => :controller
Related
rspec version: 3.5
rails version: 5.2
Controller:
def show
# Remove all source.
end
Test controller:
describe 'GET #show' do
it 'returns not found' do
get :show, params: {id: post}
expect(response).to have_http_status(:not_found)
end
end
This test case will test a 404 status, but got 500 internal server error:
expected the response to have status code :not_found (404) but it was :internal_server_error (500)
When ran the test with --backtrace:
$ rspec spec/controller/posts_controller_spec.rb --backtrace
Can found this line got error:
Failure/Error: expect(response).to have_http_status(:not_found)
expected the response to have status code :not_found (404) but it was :internal_server_error (500)
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-support-3.7.1/lib/rspec/support.rb:97:in `block in <module:Support>'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-support-3.7.1/lib/rspec/support.rb:106:in `notify_failure'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/expectations/fail_with.rb:35:in `fail_with'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/expectations/handler.rb:40:in `handle_failure'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/expectations/handler.rb:27:in `with_matcher'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/given_core-3.8.0/lib/given/rspec/monkey.rb:21:in `handle_matcher'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-expectations-3.7.0/lib/rspec/expectations/expectation_target.rb:65:in `to'
# ./spec/controllers/posts_controller_spec.rb:8:in `block (4 levels) in <top (required)>'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:254:in `instance_exec'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:254:in `block in run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:466:in `block in run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:606:in `block in run_around_example_hooks_for'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:342:in `call'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-rails-3.7.2/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:608:in `block (2 levels) in run_around_example_hooks_for'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:342:in `call'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-rails-3.7.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:608:in `block (2 levels) in run_around_example_hooks_for'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:342:in `call'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:609:in `run_around_example_hooks_for'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:466:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:251:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:628:in `block in run_examples'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:624:in `map'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:624:in `run_examples'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:590:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:591:in `block in run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:591:in `map'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:591:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:591:in `block in run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:591:in `map'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/example_group.rb:591:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:118:in `block (3 levels) in run_specs'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:118:in `map'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:118:in `block (2 levels) in run_specs'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1926:in `with_suite_hooks'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:113:in `block in run_specs'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/reporter.rb:79:in `report'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:112:in `run_specs'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:87:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'
# /Users/user/.rbenv/versions/2.3.3/bin/rspec:23:in `load'
# /Users/user/.rbenv/versions/2.3.3/bin/rspec:23:in `<main>'
So is it the version conflict between rspec-rails and rails?
In your code
def show
# Remove all source.
end
There is no render or redirect code in this method, So it will try to render the implicit view show.html.erb. But if you don't have that view defined, it will return 500(internal server error)
If you just want to show not found, then give
def show
head :not_found
end
I have a model Event
class Event < ActiveRecord::Base
belongs_to :approved_by, class_name: 'User', foreign_key: 'approved_by'
end
And a model User which does not care about the reverse relation
class User < ActiveRecord::Base
include Authenticatable
end
With a Event factory like so:
FactoryGirl.define do
factory :event do
title "MyString"
description "...snip..."
start_time "2017-06-26 15:31:55"
end_time "2017-06-26 15:31:55"
venue "MyPlace"
status :active
approved_by { build :user }
trait :pending do
status :pending
approved_by nil
end
trait :active do
#no-op
end
end
end
When I try to assert that they factory works as intended, like so...
RSpec.describe Event, type: :model do
describe 'sanity checks' do
it { expect(build :event).to be_valid }
it { expect(create :event).to be_persisted }
end
end
I get the following errors:
```
drew$ rspec -b spec/models/event_spec.rb
FF
Failures:
1) Event sanity checks
Failure/Error: it { expect(build :event).to be_valid }
ActiveModel::MissingAttributeError:
can't write unknown attribute `approved_by`
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute.rb:138:in `with_value_from_database'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_set.rb:39:in `write_from_user'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods.rb:373:in `[]='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/singular_association.rb:17:in `writer'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:123:in `approved_by='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `public_send'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:12:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy/build.rb:9:in `result'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/models/event_spec.rb:5:in `block (3 levels) in <top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-rails-3.5.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:251:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:589:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1835:in `with_suite_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:111:in `run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:87:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `load'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `<main>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `eval'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `<main>'
2) Event sanity checks
Failure/Error: it { expect(create :event).to be_persisted }
ActiveModel::MissingAttributeError:
can't write unknown attribute `approved_by`
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute.rb:138:in `with_value_from_database'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_set.rb:39:in `write_from_user'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/attribute_methods.rb:373:in `[]='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/singular_association.rb:17:in `writer'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activerecord-4.2.5/lib/active_record/associations/builder/association.rb:123:in `approved_by='
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `public_send'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `each'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `tap'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/attribute_assigner.rb:14:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/evaluation.rb:12:in `object'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy/create.rb:9:in `result'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory.rb:42:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:29:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/activesupport-4.2.5/lib/active_support/notifications.rb:166:in `instrument'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/factory_runner.rb:28:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/models/event_spec.rb:6:in `block (3 levels) in <top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:254:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-rails-3.5.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:443:in `instance_exec'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:375:in `execute_with'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:338:in `call'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/hooks.rb:464:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:453:in `with_around_example_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example.rb:251:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:627:in `block in run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:623:in `run_examples'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:589:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `block in run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:590:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `map'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1835:in `with_suite_hooks'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:111:in `run_specs'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:87:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/drew/.rvm/gems/ruby-2.2.6/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `load'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/rspec:23:in `<main>'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `eval'
# /Users/drew/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:15:in `<main>'
Finished in 0.75142 seconds (files took 2.6 seconds to load)
2 examples, 2 failures
Failed examples:
rspec ./spec/models/event_spec.rb:5 # Event sanity checks
rspec ./spec/models/event_spec.rb:6 # Event sanity checks
```
However when I try this via console it works fine...
[4] pry(main)> e = FactoryGirl.build(:event)
=> #<Event:0x007fe5ef1643d8
id: nil,
title: "MyString",
description:
"..snip..",
start_time: Mon, 26 Jun 2017 15:31:55 UTC +00:00,
end_time: Mon, 26 Jun 2017 15:31:55 UTC +00:00,
venue: "MyPlace",
main_image_cloudinary_id: nil,
status: 1,
approved_by: nil,
created_at: nil,
updated_at: nil>
[5] pry(main)> e.approved_by
=> #<User:0x007fe5ef157340
id: nil,
name: "Luther Johnston",
email: "guadalupe#brakus.com",
password_hash: "...snip...",
authentication_token: "...snip...",
activation_token: nil,
activation_date: Tue, 27 Jun 2017 00:00:00 UTC +00:00,
reset_password_token: nil,
created_at: nil,
updated_at: nil>
Since I rubber ducked myself about 2 seconds after hitting the post button, I'll go ahead and answer it.
My test database and development database were out of sync.
Running rake db:test:prepare solved the issue.
I'm getting some strange results from view specs
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
Ok, so this seems self explanatory (though I'm not sure what are the 3 arguments referenced).
However, if I run the suite again, I might get 0 errors. And the next, 5 errors, of the same type as above but referencing different DOM elements.
There is nothing fancy in any of these specs
describe do
build :object / create :object
#object = assign(:object, object )
it 'displays the DOM elements' do
render
asset_select #DOM_elements
end
end
What could cause this kind of inconsistent coverage of view specs?
An example stack trace
Failure/Error: assert_select "div.fileinput-new.thumbnail"
ArgumentError:
wrong number of arguments (3 for 1)
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/actionview-4.2.6/lib/action_view/helpers/text_helper.rb:52:in `concat'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:165:in `evaluate'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:165:in `block in xpath'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:156:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:156:in `xpath'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/searchable.rb:193:in `css_internal'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:76:in `block in css'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:75:in `inject'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:75:in `css'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb:20:in `select'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
# ./spec/views/users/settings/profile.html.erb_spec.rb:24:in `block (4 levels) in <top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:295:in `nest_selection'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:177:in `block in assert_select'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `tap'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rails-dom-testing-1.0.7/lib/rails/dom/testing/assertions/selector_assertions.rb:174:in `assert_select'
# ./spec/views/users/settings/profile.html.erb_spec.rb:22:in `block (3 levels) in <top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:236:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `block in with_around_and_singleton_context_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `block in with_around_example_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:618:in `block in run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-rails-3.4.2/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:425:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:425:in `instance_exec'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:389:in `execute_with'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:620:in `block (2 levels) in run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:320:in `call'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:621:in `run_around_example_hooks_for'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/hooks.rb:478:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:435:in `with_around_example_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:478:in `with_around_and_singleton_context_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example.rb:233:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:581:in `block in run_examples'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:577:in `run_examples'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:543:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `block in run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:544:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (3 levels) in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `map'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:119:in `block (2 levels) in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1680:in `with_suite_hooks'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:118:in `block in run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/reporter.rb:77:in `report'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:117:in `run_specs'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:93:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/rspec:23:in `load'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/rspec:23:in `<main>'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/ruby_executable_hooks:15:in `eval'
# /Users/me/.rvm/gems/ruby-2.2.3#myapp/bin/ruby_executable_hooks:15:in `<main>'
This is not a definitive answer: it appears that, for some weird reason, the evaluate method in the Nokogiri's Searchable module considers the concat() function as a custom XPath function instead of the internal XPath function.
External XPath functions are called as normal ruby methods in the context of the handler attribute of evaluate. Normally the handler is the SubstitutionContext class but in your case it seems that sometimes this gets the context of the TextHelper module where the concat method is defined, accepting just 1 parameter (whereas the XPath's concat() function accepts any number of parameters). I think that this can lead to the errors you observe.
Could you open the searchable.rb file (see the stack trace for its location) on this line and add before it some debug messages to inspect the contents of the following variables?
puts "ctx #{ctx.inspect}"
puts "path #{path.inspect}"
puts "handler #{handler.inspect}"
if handler.respond_to?(:concat)
puts "concat #{handler.method(:concat).inspect}"
else
puts "not responding to :concat"
end
Then, can you provide the output printed for one of the failing tests?
Update: the output showed that indeed the tests context was being polluted by the ActionView::TextHelpers module and in the end it turned out that there was a ActionView::Helpers module included in a model used in the tests.
Have a basic helper test:
require 'rails_helper'
describe BuilderHelper do
...
describe 'press events classes' do
let(:account) { create(:candidate_profile).account }
before { allow_any_instance_of(Object).to receive(:current_account).and_return account }
specify do
expect_any_instance_of(PublicPage).to receive(:show_press?).and_return true
expect_any_instance_of(PublicPage).to receive(:show_events?).and_return true
expect(press_events_classes(account)).to eq 'section'
end
...
end
...
end
And it gives strange error:
Failure/Error: before { allow_any_instance_of(Object).to receive(:current_account).and_return account }
NoMethodError:
undefined method `unbind' for #<Proc:0x00000009803640>
# ./spec/helpers/builder_helper_spec.rb:27:in `block (3 levels) in <top (required)>'
# ./spec/support/vcr.rb:16:in `block (2 levels) in <top (required)>'
(that's it, that's the whole error log)
So the error is in before block.
The problem is that I don't have an "unbind" method anywhere.
I looked in Rails repo - it doesn't seem to have anything too.
Don't know what's the problem. Can anyone help where to look?
Update
Alright, thanks to comment I got this:
1) BuilderHelper press events classes
Failure/Error: before { allow_any_instance_of(Object).to receive(:current_account).and_return account }
NoMethodError:
undefined method `unbind' for #<Proc:0x000000025ff9e0>
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/proxy.rb:372:in `original_unbound_method_handle_from_ancestor_for'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/proxy.rb:355:in `original_method_handle_for'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:28:in `original_method'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:57:in `define_proxy_method'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:50:in `configure_method'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/method_double.rb:150:in `add_stub'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/proxy.rb:112:in `add_stub'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:38:in `block in stub'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:81:in `map'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:81:in `perform_proxying'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/any_instance/proxy.rb:37:in `stub'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/matchers/receive.rb:88:in `setup_method_substitute'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/matchers/receive.rb:81:in `setup_any_instance_method_substitute'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/matchers/receive.rb:49:in `setup_any_instance_allowance'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/targets.rb:45:in `define_matcher'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-mocks-3.0.4/lib/rspec/mocks/targets.rb:14:in `block in delegate_to'
# ./spec/helpers/builder_helper_spec.rb:27:in `block (3 levels) in <top (required)>'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:349:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `block in run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `each'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:410:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:485:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:340:in `run_before_example'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:147:in `block in run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-rails-3.0.2/lib/rspec/rails/adapters.rb:72:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# ./spec/support/vcr.rb:16:in `block (2 levels) in <top (required)>'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:294:in `instance_exec'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `call'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:432:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/hooks.rb:485:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:303:in `with_around_example_hooks'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example.rb:145:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `map'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:490:in `run_examples'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:457:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `block in run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `map'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/example_group.rb:458:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `map'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/reporter.rb:54:in `report'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:108:in `run_specs'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:86:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
# /home/dell/.rvm/gems/ruby-2.1.5/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
# /home/dell/.rvm/gems/ruby-2.1.5/bin/rspec:23:in `load'
# /home/dell/.rvm/gems/ruby-2.1.5/bin/rspec:23:in `<main>'
# /home/dell/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
# /home/dell/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Still not sure what to do.
Update
Solved by replacing this:
before { allow_any_instance_of(Object).to receive(:current_account).and_return account }
With this:
before { allow_any_instance_of(BuilderHelper).to receive(:current_account).and_return account }
So my best guess which is hard to tell base on this but what I had happen was I in fact stubbed out the find and returned a proc object in its place.
let(:record) { create :record } # This is a Proc
allow(Object).to receive(:find).and_return(record)
allow_any_instance_of(Object).to receive(:update) # This calls unbind
Sadly trying to figure out where the first stub happened. But I bet it is there in your code.
I have a simple spec:
describe Setting do
subject { create(:setting) }
it { should be_valid }
end
with the factory:
FactoryGirl.define do
factory :setting do
key "some_key"
value "The appropriate value"
end
end
When I run the spec:
rake spec SPEC=spec/models/setting_spec.rb
I get the following error:
1) Setting should be valid
Failure/Error: it { should be_valid }
NoMethodError:
undefined method `to_sym' for nil:NilClass
# ./spec/models/setting_spec.rb:6:in `block (2 levels) in <top (required)>'
I tried using a let(:setting) in place of the subject line and got the same error.
EDIT Per comments:
The error refers to the line it { should be_valid }
The model is:
class Setting < ActiveRecord::Base
attr_accessor :key, :value
validates_uniqueness_of :key
end
Here's the trace:
# /var/lib/gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/validations/uniqueness.rb:26:in `validate_each'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:153:in `block in validate'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:150:in `each'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validator.rb:150:in `validate'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:310:in `_callback_before_1986'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:407:in `_run__3464288744618424855__validate__1974049388273351148__callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations.rb:228:in `run_validations!'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:403:in `_run__3464288744618424855__validation__1974049388273351148__callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
# /var/lib/gems/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
# /var/lib/gems/1.9.1/gems/activemodel-3.2.16/lib/active_model/validations.rb:195:in `valid?'
# /var/lib/gems/1.9.1/gems/activerecord-3.2.16/lib/active_record/validations.rb:69:in `valid?'
# /var/lib/gems/1.9.1/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:24:in `handle_matcher'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/memoized_helpers.rb:68:in `should'
# ./spec/models/setting_spec.rb:6:in `block (2 levels) in <top (required)>'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `instance_eval'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:114:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:111:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `run_examples'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:371:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `map'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:58:in `report'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:25:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:77:in `rescue in run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:73:in `run'
# /var/lib/gems/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
spec_helper.rb: http://pastebin.com/6fzDXnux
The direct cause for this error is that the class derives from ActiveRecord::Base, and ActiveRecord can't determine the primary key (required by AR for validating uniqueness). Most likely, this is happening either because you haven't run migrations to create the settings table, or you created the settings table without a primary key.
The offending line (based on the backtrace provided):
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
Note that to_sym is being called on finder_class.primary_key.
you can also solve same by adding below line in your model.
self.primary_key = 'id'
e.g.
Class Person
self.primary_key = 'id'
end