When I try to lauch webbrick from my terminal using rails server, This is what I get and webbrick shuts down, what could be the problem.
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
Following the shutdown I get this huge error which absolutely makes no sense to me.
/Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:229:in `default_controller_and_action': missing :controller (ArgumentError)
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:116:in `normalize_options!'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:64:in `initialize'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1443:in `new'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1443:in `add_route'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1422:in `decomposed_match'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1403:in `block in match'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1394:in `each'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1394:in `match'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:601:in `map_method'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:562:in `get'
from /Users/Fulcrum/Sites/recrea8/config/routes.rb:14:in `block in <top (required)>'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:319:in `draw'
from /Users/Fulcrum/Sites/recrea8/config/routes.rb:1:in `<top (required)>'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `call'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `execute'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/Fulcrum/Sites/recrea8/config/environment.rb:5:in `<top (required)>'
from /Users/Fulcrum/Sites/recrea8/config.ru:3:in `require'
from /Users/Fulcrum/Sites/recrea8/config.ru:3:in `block in <main>'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/Fulcrum/Sites/recrea8/config.ru:in `new'
from /Users/Fulcrum/Sites/recrea8/config.ru:in `<main>'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:48:in `app'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:75:in `start'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
from /Users/Fulcrum/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
This is my route.rb
Recrea8::Application.routes.draw do
resources :sessions
resources :users
resources :categories
resources :characters
resources :industries
resources :nationalities
resources :personalities
resources :project_types
resources :projects
get 'logout', 'sessions#destroy', as: 'logout'
match ':controller(/:action(/:id))', :via => [:get, :post]
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'users#new'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
Try to change lines:
#get 'logout', 'sessions#destroy', as: 'logout'
get 'logout' => 'sessions#destroy', as: 'logout'
And
#root 'users#new'
root to: 'users#new'
Related
I am creating automated tests for my rails app using rspec and factoryBot. In my case I am creating a company with a requirement of having a logo. Creating a company in the test is not a problem but if I try and modify the company outside of the test file I am getting an error message of
ActiveRecord::RecordInvalid:
Validation failed: Logo can't be blank
I have tried alternative upload methods but with no luck. Below is the factory for the company and the process I am using to create a company. This is not the exact code in my implementation as I am unable to share that but I have replicated it as much as I could.
If I manually test the code it works fine. It is only when running the code with rspec the error occurs.
factories.rb
FactoryBot.define do
factory :company do
name { 'Name' }
b_day { Date.today }
age { 1 }
logo { Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, '/spec/support/logo.png')), 'image/png') }
end
end
companies_rake_spec.rb
describe "Company b_day today" do
it "Add 1 to company age" do
company1 = create(:company)
Rake::Task['companies:update_age'].invoke
company1_refresh = Company.where(id: company1.id).first
expect(company1_refresh.age).to eq(company1.age + 1)
end
end
company.rake
namespace :companies do
desc "TODO"
task update_age: :environment do
Company.find_each do | company |
if (company.b_day.day == Date.today.day) && (company.b_day.month == Date.today.month)
company.age += 1
puts company.inspect
company.save!
end
end
end
end
end
console
#<Company id: 34, name: "Name", b_day: 2018-11-13, age: 2, logo: "1cbeef36f13a8a88db0c37fa30da6ffd.png">
ActiveRecord::RecordInvalid:
Validation failed: Logo can't be blank
stacktrace
Failures:
1) companies:update_age age + 1
Failure/Error: company.save!
ActiveRecord::RecordInvalid:
Validation failed: Logo can't be blank
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/validations.rb:78:in `raise_validation_error'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/validations.rb:50:in `save!'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/transactions.rb:324:in `block in save!'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/transactions.rb:211:in `transaction'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/transactions.rb:324:in `save!'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/suppressor.rb:45:in `save!'
# ./lib/tasks/companies.rake:54:in `block (3 levels) in <top (required)>'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:59:in `block (2 levels) in find_each'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:59:in `each'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:59:in `block in find_each'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:121:in `block in find_in_batches'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:214:in `block in in_batches'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:198:in `loop'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:198:in `in_batches'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:120:in `find_in_batches'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/relation/batches.rb:58:in `find_each'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/activerecord-5.0.7/lib/active_record/querying.rb:9:in `find_each'
# ./lib/tasks/companies.rake:8:in `block (2 levels) in <top (required)>'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/lib/rake/task.rb:271:in `block in execute'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/lib/rake/task.rb:271:in `each'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/lib/rake/task.rb:271:in `execute'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
# /Users/mac/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/lib/rake/task.rb:193:in `invoke_with_call_chain'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rake-12.3.1/lib/rake/task.rb:182:in `invoke'
# ./spec/lib/tasks/companies_rake_spec.rb:122:in `block (3 levels) in <top (required)>'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:254:in `instance_exec'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:254:in `block in run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in `block in run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in `call'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-rails-3.8.0/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in `execute_with'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in `call'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in `run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:251:in `run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:629:in `block in run_examples'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in `map'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in `run_examples'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:591:in `run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `block in run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `map'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `block (3 levels) in run_specs'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `map'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `block (2 levels) in run_specs'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1989:in `with_suite_hooks'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:111:in `block in run_specs'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:74:in `report'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:110:in `run_specs'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:87:in `run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/mac/.rvm/gems/ruby-2.5.1/gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
# /Users/mac/.rvm/gems/ruby-2.5.1/bin/rspec:23:in `load'
# /Users/mac/.rvm/gems/ruby-2.5.1/bin/rspec:23:in `<main>'
# /Users/mac/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:15:in `eval'
# /Users/mac/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:15:in `<main>'
How to properly do model testing with ActiveStorage in rails?
Using the info from there and adapting to your specifics, try the following factory:
FactoryBot.define do
factory :company do
name { 'Name' }
b_day { Date.today }
age { 1 }
after(:build) do |company|
company.logo.attach(io: File.open(Rails.root.join('spec', 'support', 'logo.jpeg')), filename: 'logo.jpeg', content_type: 'image/jpeg')
end
end
end
EDIT:
You may also need to add this to your config/environments/test.rb file:
config.active_storage.service = :test
I have a grape entity for a Contact model, which references User model twice:
class Contact < ApplicationRecord
belongs_to :user, foreign_key: :user_id
belongs_to :contact, class_name: 'User', foreign_key: :contact_id
def entity
Entity.new(self)
end
class Entity < Grape::Entity
expose :contact do
expose :id
expose :user, as: :inviter, merge: true, using: User::Entity
expose :contact, as: :invitee, merge: true, using: User::Entity
expose :status
end
end
end
When I get an endpoint which presents contact, I have the following error
ArgumentError:
wrong number of arguments (given 3, expected 0)
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure/output_builder.rb:53:in `block in merge_strategy'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure/output_builder.rb:19:in `merge!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure/output_builder.rb:19:in `add'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:62:in `block (2 levels) in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:108:in `block in with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/options.rb:102:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:107:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:61:in `block (2 levels) in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:108:in `block in with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/options.rb:102:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/base.rb:107:in `with_attr_path'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:60:in `block in serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `each_with_object'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/exposure/nesting_exposure.rb:59:in `serializable_value'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-entity-0.6.1/lib/grape_entity/entity.rb:473:in `serializable_hash'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/formatter/json.rb:6:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:44:in `block in build_formatted_response'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:44:in `collect'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:44:in `build_formatted_response'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/formatter.rb:28:in `after'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:34:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:31:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:31:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/error.rb:34:in `block in call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/error.rb:33:in `catch'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/error.rb:33:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/middleware/base.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/endpoint.rb:224:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/endpoint.rb:218:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router/route.rb:72:in `exec'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:119:in `process_route'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:74:in `block in identity'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:93:in `transaction'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:72:in `identity'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:57:in `block in call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:135:in `with_optimization'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/router.rb:56:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/api.rb:119:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/api.rb:45:in `call!'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/grape-0.19.1/lib/grape/api.rb:40:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/etag.rb:25:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/conditional_get.rb:25:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:36:in `call_app'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `block in call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/engine.rb:522:in `call'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /home/doimhneacht/.rvm/gems/ruby-2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:124:in `request'
# ./spec/requests/contacts_spec.rb:39:in `block (4 levels) in <top (required)>'
How to make it include User entities for both inviter and invitee in the Contact entity?
undefined local variable or method `login_user'
Why are my controllers not getting the extended ControllerMacros ???
Commit in question: https://github.com/shadowbq/cartoque/commit/2fba99c6eac5f9f2f0da2dd464f475cae0bae520
<snip>
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
<...snip>
<snip>
# include devise helpers in controller specs
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
<...snip>
/usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:675:in `method_missing': undefined local variable or method `login_user' for RSpec::ExampleGroups::BackupExclusionsController:Class (NameError)
from /home/shadowbq/sandbox/cartoque/spec/controllers/backup_exlusions_controller_spec.rb:5:in `block in <top (required)>'
<snip>
module ControllerMacros
def login_admin
before(:each) do
#request.env["devise.mapping"] = Devise.mappings[:admin]
#user = FactoryGirl.create(:admin)
sign_in #user
end
end
def login_user
before(:each) do
#request.env["devise.mapping"] = Devise.mappings[:user]
#user = FactoryGirl.create(:user)
sign_in #user
end
end
end
<...snip>
Here is full backtrace as well..
/usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:675:in `method_missing': undefined local variable or method `login_user' for RSpec::ExampleGroups::BackupExclusionsController:Class (NameError)
from /home/shadowbq/sandbox/cartoque/spec/controllers/backup_exlusions_controller_spec.rb:5:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:385:in `module_exec'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:385:in `subclass'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/example_group.rb:255:in `block in define_example_group_method'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/dsl.rb:82:in `block (2 levels) in expose_example_group_alias_globally'
from /home/shadowbq/sandbox/cartoque/spec/controllers/backup_exlusions_controller_spec.rb:3:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in `load'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in `each'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:102:in `setup'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in `run'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in `load'
from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'
More file snippets
root#ubuntu:/home/shadowbq/sandbox/cartoque# head -15 spec/controllers/backup_exlusions_controller_spec.rb
require 'spec_helper'
describe BackupExclusionsController do
login_user
before do
#backup_exclusion = BackupExclusion.create
end
it "gets index" do
get :index
assert_response :success
assert_not_nil assigns(:backup_exclusions)
end
https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29
In rspec-rails 3, specs no longer have their type set automatically based on path, so your controller specs no longer have type :controller. You can either:
reneebable this with the config.infer_spec_type_from_file_location! option
explicitly tag your controller specs with type: :controller
I am using ruby "2.0.0" and 'rails', '~> 4.0.0' and 'rspec-rails', "2.14.2" ( quoted from the Gemfile. I have two entirely different apps and I am getting the same error on both.
I used the scaffold generator for my controller. So it also generated my controller tests. In particular the update action broke right away.
Test code
describe "PUT update" do
describe "with valid params" do
it "updates the requested product" do
product = Product.create! valid_attributes
# Assuming there are no other products in the database, this
# specifies that the Product created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
expect_any_instance_of(Product).to receive(:update).with({ "product_name" => "Product 1" })
put :update, {:id => product.to_param, :product => { "product_name" => "Product 1" }}, valid_session
end
Controller code:
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
def update
respond_to do |format|
if #product.update_attributes(product_params)
format.html { redirect_to #product, notice: 'Product was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: #product.errors, status: :unprocessable_entity }
end
end
end
So i run my test and:
1) ProductsController PUT update with valid params updates the requested product
Failure/Error: Unable to find matching line from backtrace
Exactly one instance should have received the following message(s) but didn't: update
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-mocks-3.0.2/lib/rspec/mocks/any_instance/recorder.rb:92:in `verify'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-mocks-3.0.2/lib/rspec/mocks/space.rb:69:in `block in verify_all'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-mocks-3.0.2/lib/rspec/mocks/space.rb:69:in `each_value'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-mocks-3.0.2/lib/rspec/mocks/space.rb:69:in `verify_all'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-mocks-3.0.2/lib/rspec/mocks.rb:45:in `verify'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/mocking_adapters/rspec.rb:21:in `verify_mocks_for_rspec'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:354:in `verify_mocks'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:345:in `run_after_example'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:163:in `block in run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:210:in `call'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-rails-3.0.1/lib/rspec/rails/example/controller_example_group.rb:174:in `block (2 levels) in <module:ControllerExampleGroup>'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:294:in `instance_exec'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:294:in `instance_exec'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:210:in `call'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:68:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:294:in `instance_exec'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:294:in `instance_exec'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:210:in `call'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/hooks.rb:432:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/hooks.rb:485:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:303:in `with_around_example_hooks'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example.rb:145:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:494:in `block in run_examples'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:490:in `map'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:490:in `run_examples'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:457:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:458:in `block in run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:458:in `map'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:458:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:458:in `block in run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:458:in `map'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/example_group.rb:458:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:112:in `map'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:112:in `block in run_specs'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/reporter.rb:54:in `report'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:108:in `run_specs'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:86:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in `run'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:in `invoke'
# /Users//.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-3.0.2/exe/rspec:4:in `<top (required)>'
# /Users//.rvm/gems/ruby-2.0.0-p353/bin/rspec:23:in `load'
# /Users//.rvm/gems/ruby-2.0.0-p353/bin/rspec:23:in `<main>'
# /Users//.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
# /Users//.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
Finished in 0.27911 seconds (files took 1.85 seconds to load)
16 examples, 1 failure
Failed examples:
rspec ./spec/controllers/products_controller_spec.rb:90 # ProductsController PUT update with valid params updates the requested product
I am posting the response after this, the problem is solved:
So a good friend took a glance at my code and he pointed out that:
expect_any_instance_of(Product).to receive(:update).with({ "product_name" => "Product 1" })
Is trying to receive an update from the model. There is no update method on the model:
class Product < ActiveRecord::Base
before_validation :normalize_name, on: :create
validates :product_name, presence: true, uniqueness: true
validates :product_cost, presence: true, :numericality => { :greater_than_or_equal_to => 1 }
protected
def normalize_name
self.product_name = self.product_name.downcase.titleize
end
end
So the fix consists in adding :update_attributes to the tests in order to make the call to the model, instead as a controller action as it was doing before.
expect_any_instance_of(Product).to receive(:update_attributes).with({ "product_name" => "Product 1" })
And now the test pass.
I hope this helps. I am fairly new to Rails, so please bear with any inaccuracies or errors. Feel free to report typos or corrections, they are always welcome.
Having looked into it, and as a relative newbie to graph databases, I've decided that Neoid may be the best way to benefit from Neo4j at this stage. I've come across a problem straight after installing it, on starting up the server. I've installed the gem, added the 01_neo4j.rb file as stated on the github page, added the relevant columns to the models and get the following error:
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/open-uri.rb:35:in `initialize': No such file or directory - /dev/null (Errno::ENOENT)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/open-uri.rb:35:in `open'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/open-uri.rb:35:in `open'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/logger.rb:599:in `create_logfile'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/logger.rb:594:in `open_logfile'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/logger.rb:549:in `initialize'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/logger.rb:314:in `new'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/logger.rb:314:in `initialize'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/neoid-0.1.2/lib/neoid.rb:73:in `new'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/neoid-0.1.2/lib/neoid.rb:73:in `logger'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/neoid-0.1.2/lib/neoid.rb:52:in `initialize_all'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/neoid-0.1.2/lib/neoid/railtie.rb:7:in `block (2 levels) in <class:Railtie>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:180:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from C:/Sites/Knock4/config/environment.rb:5:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from C:/Sites/Knock4/config.ru:3:in `block in <main>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from C:/Sites/Knock4/config.ru:in `new'
from C:/Sites/Knock4/config.ru:in `<main>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands/server.rb:48:in `app'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands/server.rb:75:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
If anyone has any idea what the problem might be here, I would appreciate it. I'm using Rails 4.0.2 (as you can probably see), so not sure if this is an issue.
The error reference shows the following code:
def open(name, *rest, &block) # :doc:
if name.respond_to?(:open)
name.open(*rest, &block)
elsif name.respond_to?(:to_str) &&
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
(uri = URI.parse(name)).respond_to?(:open)
uri.open(*rest, &block)
else
open_uri_original_open(name, *rest, &block)
end
end
With
open_uri_original_open(name, *rest, &block)
being line 35. I have no idea what this means though!
This is caused, on windows, by neoid 0.1.2 which assumes you are on unix and so the standard logger redirects to dev/null. So you must define
ENV['NEOID_LOG'] ||= 'true'
ENV['NEOID_LOG_FILE'] ||= 'log/neoid.log'
and the log will be in the log folders.