rspec

Error loading rubygems

醉酒当歌 提交于 2019-12-23 02:52:41
问题 During an operation (rspec related) that required loading rubygems (from config/boot.rb file) I got the following error message: ~/config/boot.rb:1:in `require': no such file to load -- rubygems (LoadError) ~/config/boot.rb:1 from ~/config/application.rb:1:in `require' from ~/config/application.rb:1 from ~/config/environment.rb:2:in `require' from ~/config/environment.rb:2 from ~/spec/spec_helper.rb:3:in `require' from ~/spec/spec_helper.rb:3 from ~/spec/models/user_spec.rb:1:in `require'

capybaraWebKit is unable to visit webpages when running RSpec tests when :js => true

怎甘沉沦 提交于 2019-12-23 01:59:31
问题 On previous RSpec integration tests where :js => false (i.e., JavaScript was turned off), my tests were running just fine. However, for RSpec tests where :js => true (and therefore needing to use capybara WebKit), I consistently get the following error: Unable to load URL: http://my.server:5000/auth/identity because of error loading http://my.server:5000/auth/identity: Unknown error Noted this is happening on a line of code that was working just fine when :js => false (it is part of a method

Factory Girl - Why are Records being continually created?

╄→гoц情女王★ 提交于 2019-12-23 01:45:42
问题 I'm new to factory girl. What I'm trying to do is create 2 users, which belong to a group, joined by the permission model. Here's what I have. When I run this one rspec, it creates more than 2 users, 4+. Why? thanks factories.rb: require 'factory_girl' Factory.define :user do |f| f.sequence(:fname) { |n| "fname#{n}" } f.sequence(:lname) { |n| "lname#{n}" } f.sequence(:email) { |n| "email#{n}@google.com" } f.password "password" f.password_confirmation { |u| u.password } f.invitation_code

Rails carrierwave testing - how to remove file after test?

人走茶凉 提交于 2019-12-23 01:16:32
问题 I am testing the carrierwave upload functionality using rspec and capybara. I have something like: describe "attachment" do let(:local_path) { "my/file/path" } before do attach_file('Attachment file', local_path) click_button "Save changes" end specify {user.attachment.should_not be_nil} it { should have_link('attachment', href: user.attachment_url) } end And this works great. The problem is that after testing the uploaded image remains in my public/uploads directory. How can I remove it

Factory Girl with enum and association

笑着哭i 提交于 2019-12-23 00:52:10
问题 I have a model that uses both an association and an enum attribute. class ProjectItem < ActiveRecord::Base belongs_to :project enum status: {open: 0, pending: 1, completed: 2} When I'm running a test on the create action of a model with an association, I use build(:model_name).attributes like this: it "creates a new ProjectItem" do expect { post :create, document_project_item: build(:project_item).attributes }.to change(ProjectItem, :count).by(1) end This was failing, and I found this issue

Set variable once for all examples in RSpec suite (without using a global variable)

烈酒焚心 提交于 2019-12-22 18:42:50
问题 What is the conventional way to set a variable once to be used by all examples in an RSpec suite? I currently set a global variable in spec_helper that checks whether the specs are being run in a "debug mode" $debug = ENV.key?('DEBUG') && (ENV['DEBUG'].casecmp('false') != 0) && (ENV['DEBUG'].casecmp('no') != 0) How do I make this information available to all the examples in the suite without using a global variable and without re-computing the value for each context and/or example? (My

rspec: undefined local variable or method `be_true'

自作多情 提交于 2019-12-22 13:48:31
问题 I am using rspec 2.4.0 and cucumber 0.6.4. I am running a simple scenario (for the sake of this question): Scenario: Simple Test When I test something with step definition: require 'rspec' require 'rspec/expectations' When /^I test something$/ do result = (1==1) result.should be_true end When I run this scenario I get the following problems: undefined local variable or method `be_true' for #<Object:0x1b3b424> (NameError) I am also using bundler to manage my dependencies. Am I doing something

RSpec controller test failing with Rails API - Undefined Method 'helpers'

这一生的挚爱 提交于 2019-12-22 12:43:38
问题 I'm trying to follow this Rails API Guide to better understand how to integrate the Rails API into my own application, however my RSpec test is failing on the routing expectation and I'm not sure why. My error message is 1) Api::V1::UsersController POST #create when is not created renders an errors json Failure/Error: expect(user_response).to have_key(:errors) NoMethodError: undefined method "helpers" for # <ActionDispatch::Routing::RouteSet::NamedRouteCollection:0x007f7f8a1c0938> Did you

RSpec controller test failing with Rails API - Undefined Method 'helpers'

守給你的承諾、 提交于 2019-12-22 12:42:33
问题 I'm trying to follow this Rails API Guide to better understand how to integrate the Rails API into my own application, however my RSpec test is failing on the routing expectation and I'm not sure why. My error message is 1) Api::V1::UsersController POST #create when is not created renders an errors json Failure/Error: expect(user_response).to have_key(:errors) NoMethodError: undefined method "helpers" for # <ActionDispatch::Routing::RouteSet::NamedRouteCollection:0x007f7f8a1c0938> Did you

How to test google analytics (garb) API with Rspec?

99封情书 提交于 2019-12-22 12:37:59
问题 I'm using the garb gem to pull some basic stats, like pageviews, from Google Analytics. Everything's working correctly but I can't figure out the best way to test my API calls. Here's a paired down version of my Analytics class: class Analytics extend Garb::Model metrics :pageviews dimensions :page_path Username = 'username' Password = 'password' WebPropertyId = 'XX-XXXXXXX-X' # Start a session with google analytics. # Garb::Session.login(Username, Password) # Find the correct web property. #