rspec core Ruby on Rails -
hello i'm testing application rspec:
this test file.
require 'spec_helper' describe recipescontroller render_views describe "index" before recipe.create!(name: "spaghetti alla carbonara") recipe.create!(name: "spaghetti alle vongole e cozze") recipe.create!(name: "bistecca") recipe.create!(name: "fritto") xhr :get, :index, format: :json, keywords: keywords end subject(:results) { json.parse(response.body) } def extract_name ->(object){ object["name"] } end context 'quando la ricerca riporta dei risultati' let(:keywords) { 'spaghetti' } 'essere 200' expect(response.status).to eq(200) end 'deve ritornare due risultati' expect(results.size).to eq(2) end 'deve esserci la ricetta spaghetti alla carbonara' expect(results.map(&extract_name)).to include('spaghetti alla carbonara') end 'deve esserci la ricetta spaghetti alle vongole e cozze ' expect(results.map(&extract_name)).to include('spaghetti alle vongole e cozze') end end context 'quando la ricerca non riporta alcun risulato' let(:keywords) { 'tortellini' } 'non deve ritornare alcun risulato' expect(results.size).to eq(0) end end end end
when try launch test via command:
rake db:migrate rails_env=test ; rspec spec/controllers/recipes_controller_spec.rb
i recive error
/var/lib/gems/2.1.0/gems/bundler-1.10.1/lib/bundler/runtime.rb:34:in
block in setup': have activated rspec-core 3.3.1, gemfile requires rspec-core 2.99.2. prepending
bundle exec` command may solve this. (gem::loaderror)
as described in log error conflict rspec-core v3.3.1 in gem file i've added line install rspec-core v2.99.2
gem 'rspec-core', '~> 2.99.2'
but if launch command again (after bundle install , bundle exec) result same. have similar problem?
did try?
bundle exec rake db:migrate rails_env=test bundle exec rspec spec/controllers/recipes_controller_spec.rb
Comments
Post a Comment