rspec

rspec association test only works in one direction

一世执手 提交于 2020-01-07 03:37:07
问题 I upgraded to Rails 3 and RSpec 2 and one of my RSpec tests stopped working: # Job.rb class Job < ActiveRecord::Base has_one :location belongs_to :company validates_associated :location end # Location.rb class Location < ActiveRecord::Base belongs_to :job end # job_spec.rb describe Job, "location" do it "should have a location" do job = Factory(:job) location = Factory(:location, :job_id => job.id) location.job.should == job #true job.location.should == location #false end end job.location

railties (LoadError) Cannot load such file

一曲冷凌霜 提交于 2020-01-07 02:23:26
问题 I've got a Ruby on Rails app, just added rspec-rails and I tried to run: rails generate rspec:install But received this: /usr/local/bin/rails:23:in `load': cannot load such file -- /usr/share /rubygems-integration/all/gems/railties-4.2.6/bin/rails (LoadError) From my Gemfile... gem 'rspec-rails', '~> 3.5' And I'm running Rails v4.2.5.1 回答1: I've just done sudo gem install rails and now it works. 来源: https://stackoverflow.com/questions/42379882/railties-loaderror-cannot-load-such-file

railties (LoadError) Cannot load such file

若如初见. 提交于 2020-01-07 02:23:19
问题 I've got a Ruby on Rails app, just added rspec-rails and I tried to run: rails generate rspec:install But received this: /usr/local/bin/rails:23:in `load': cannot load such file -- /usr/share /rubygems-integration/all/gems/railties-4.2.6/bin/rails (LoadError) From my Gemfile... gem 'rspec-rails', '~> 3.5' And I'm running Rails v4.2.5.1 回答1: I've just done sudo gem install rails and now it works. 来源: https://stackoverflow.com/questions/42379882/railties-loaderror-cannot-load-such-file

Watir webdriver; counting elements with changing class names

早过忘川 提交于 2020-01-07 02:11:11
问题 I am using Rspec and Watir-webdriver and am looking to get a count of all the elements that have been clicked. What I'm doing: I perform a search and get back a list of results; I then run a loop to select only 5 of them. The class name for these elements goes from asset-card selectable to now saying asset-card selectable selected . I try to get a proper count by doing this: count = @browser.elements(:class, 'selected').size But this is still giving me all results and not specifically the

Rspec fails with “bad value for range”

假如想象 提交于 2020-01-06 15:13:19
问题 My method: def swap (order) order = order == 'asc' ? 'desc' : 'asc' end Spec: let(:order) { 'wrong_order'} it 'swaps the order' do expect(swap(order)).to eq('asc') end This rspec is failing with the message ArgumentError: bad value for range But if i pass 'desc' or 'asc' and change the expect it works fine. Also i tried this on irb with just passing swap(' ') it gives me 'asc' not sure why rspec is failing 回答1: Try being a bit more explicit with the test: let(:order) { 'wrong_order'} it

Rspec fails with “bad value for range”

醉酒当歌 提交于 2020-01-06 15:12:15
问题 My method: def swap (order) order = order == 'asc' ? 'desc' : 'asc' end Spec: let(:order) { 'wrong_order'} it 'swaps the order' do expect(swap(order)).to eq('asc') end This rspec is failing with the message ArgumentError: bad value for range But if i pass 'desc' or 'asc' and change the expect it works fine. Also i tried this on irb with just passing swap(' ') it gives me 'asc' not sure why rspec is failing 回答1: Try being a bit more explicit with the test: let(:order) { 'wrong_order'} it

Rspec not logging me in

扶醉桌前 提交于 2020-01-06 14:13:09
问题 I was looking at this answer to see how to test a session controller and wrote something like this: require 'spec_helper' describe SessionsController do context "We should login to the system and create a session" do let :credentials do {:user_name => "MyString", :password => "someSimpleP{ass}"} end let :user do FactoryGirl.create(:user, credentials) end before :each do post :create , credentials end it "should create a session" do puts user.inspect puts session[:user_id] #session[:user_id]

Rspec not logging me in

╄→尐↘猪︶ㄣ 提交于 2020-01-06 14:12:08
问题 I was looking at this answer to see how to test a session controller and wrote something like this: require 'spec_helper' describe SessionsController do context "We should login to the system and create a session" do let :credentials do {:user_name => "MyString", :password => "someSimpleP{ass}"} end let :user do FactoryGirl.create(:user, credentials) end before :each do post :create , credentials end it "should create a session" do puts user.inspect puts session[:user_id] #session[:user_id]

Rspec error when I run my rspec test of my controller

独自空忆成欢 提交于 2020-01-06 14:10:57
问题 I am developing a Rails v2.3 application. When I run the rspec test by execute command: rspec spec/controllers/my_controller_spec.rb I got the error message which is showing below: /.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded': (RuntimeError) ******************************************************************************** You are running rspec-2, but it seems as though rspec-1 has been loaded as well. This is likely

Float not equal after division followed by multiplication

眉间皱痕 提交于 2020-01-06 08:18:12
问题 I'm testing a small and simple library I made in Ruby. The goal is to convert from EUR to CNY and vice versa. Simple. I tested it to be sure everything works but I got an unexpected issue. When I use to_euro followed by to_yuan it should go back to the original amount ; it doesn't happen. I tried to .to_f or round(2) the amount variable which fix some tests, raise new ones, but it's never equal to what I expect globally ; I'm running out of idea to fix this :( class Currency attr_reader