rspec

Rails/rspec: how to set cookies in a request spec?

自古美人都是妖i 提交于 2020-01-14 07:18:20
问题 How do I set cookies in my request specs? The solutions on the following page did not work: Rspec: setting cookies in a helper test Namely, request.cookies[:whatever] = 'something' says that request is a nil object. I also tried helper.cookies[:whatever] = 'something' , and that also did not work ( helper in that case was nil ). 回答1: Try just the following: cookies[:whatever] = 'something' 回答2: Make sure you are using the rspec-rails gem and are requiring 'rspec/rails' in your spec_helper,

How can I clear class variables between rspec tests in ruby

戏子无情 提交于 2020-01-14 07:06:07
问题 I have the following class: I want to ensure the class url is only set once for all instances. class DataFactory @@url = nil def initialize() begin if @@url.nil? Rails.logger.debug "Setting url" @@url = MY_CONFIG["my value"] end rescue Exception raise DataFactoryError, "Error!" end end end I have two tests: it "should log a message" do APP_CONFIG = {"my value" => "test"} Rails.stub(:logger).and_return(logger_mock) logger_mock.should_receive(:debug).with "Setting url" t = DataFactory.new t =

absurdly slow running rspec test

◇◆丶佛笑我妖孽 提交于 2020-01-14 06:13:43
问题 I have this very simple and short test which takes a 80 seconds to run, any advice on speed it up? require 'spec_helper' describe "Battles" do let(:character) { (FactoryGirl.create :character) } describe "Battle button" do it "redirects to battle screen" do character.init("fighter") click("Battle") expect(page).to have_content character.name end end end Gemfile source 'https://rubygems.org' ruby '2.0.0' gem 'pg', '0.15.1' gem 'rails', '4.0.2' gem 'bcrypt-ruby', '~> 3.1.2' gem 'twitter

Comparing rspec custom ActiveRecord::RecordInvalid errors messages

蓝咒 提交于 2020-01-13 19:40:50
问题 Having the following in the model : validates_uniqueness_of :title, if: proc { |item| item.item_type == 'tag' }, case_sensitive: false, message: I18n.t('errors.key', value: "%{value}") and trying to validate in rspec with the following : expect { xxx }.to raise_error( ActiveRecord::RecordInvalid, I18n.t('errors.key', value: '...passing the title...') ) Am stuck with the very close following : ActiveRecord::RecordInvalid with "translated error", got #<ActiveRecord::RecordInvalid: Validation

Comparing rspec custom ActiveRecord::RecordInvalid errors messages

天涯浪子 提交于 2020-01-13 19:39:39
问题 Having the following in the model : validates_uniqueness_of :title, if: proc { |item| item.item_type == 'tag' }, case_sensitive: false, message: I18n.t('errors.key', value: "%{value}") and trying to validate in rspec with the following : expect { xxx }.to raise_error( ActiveRecord::RecordInvalid, I18n.t('errors.key', value: '...passing the title...') ) Am stuck with the very close following : ActiveRecord::RecordInvalid with "translated error", got #<ActiveRecord::RecordInvalid: Validation

Simple way to test an HTTPS (SSL) request with RSpec

回眸只為那壹抹淺笑 提交于 2020-01-13 19:39:09
问题 I want Rspec to request the root using https. This is what I currently have: it "requesting root (/) with HTTPS should return 200" do get "https://test.host/" last_response.should be_ok end Attempting the solution proposed in Test an HTTPS (SSL) request in RSpec Rails returns the following error: wrong number of arguments (0 for 1) I would assume I could do something like: get "/", :https => "on" Is there a way to request the root without specifying the host? 回答1: When using Sinatra and RSpec

Capybara::ElementNotFound: Unable to find field “title”

陌路散爱 提交于 2020-01-13 19:22:32
问题 I could not resolve this issue. Please help me. It gives me element not found error. spec/features/todos/create_spec.rb require 'spec_helper' describe "Creating todos" do let(:user) { FactoryGirl.create(:user)} before(:each) do visit root_path click_link "Login" fill_in "Email", with: "user@gmail.com" fill_in "Password", with: "password" click_button "Sign in" end it "redirects to the todos index page" do visit "/todos" fill_in "title", with: "MyString" click_button "Create" expect(page).to

ruby 2.1 rails 4 sunspot solr tests fail in suite but pass individually

给你一囗甜甜゛ 提交于 2020-01-13 11:23:07
问题 My team has been stumped on this issue for some time now and are at a loss as to where to try next. The spec below works correctly when run individually, however, when we run this in our suite via bundle exec ./bin/rspec spec these two tests fail every single time: GET /external-products/:id/deals GET /external-products/search/deals We have tried numerous different ways to approach this issue and I am starting to suspect something else outside of the said spec. SO I have to turn to the Stack

Undefined method 'visit' for #<Class:XYZ> (NoMethodError) [rspec]

瘦欲@ 提交于 2020-01-13 05:24:39
问题 I'm getting the following error when I try to run an rspec test: /srv/offerme/spec/requests/static_pages_spec.rb:13: undefined method `visit' for #<Class:0xb3436684> (NoMethodError) from /var/lib/gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval' from /var/lib/gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `subclass' from /var/lib/gems/1.8/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:224:in `describe' from /srv/offerme/spec

RSpec and Machinist error: Too many open files

情到浓时终转凉″ 提交于 2020-01-12 19:07:05
问题 This morning I am having the following error: 14) Deal on creation sets frozen to false or nil Failure/Error: Unable to find matching line from backtrace Errno::EMFILE: Too many open files - identify -format %wx%h '/var/folders/BJ/BJcTANEBFxWcan28U2YEKE+++TI/-Tmp-/stream20120229-36866-4l1sa8.gif[0]' # ./spec/support/blueprints.rb:29:in `block in <top (required)>' Specs are so damn slow (even with spork) so they are useless. It takes 9 minutes to run 20 examples in a model. Line 29 in