Questions tagged [rspec3]

RSpec 3 is a major release of the Behaviour-Driven Development tool for Ruby programmers. Use this tag only for RSpec 3-specific questions, and add [rspec] to those questions too.

RSpec 3 is a major release of the Behaviour-Driven Development tool for Ruby programmers.

RSpec 3 introduces many new features and also removes some syntax from RSpec 2. The last release of RSpec 2, RSpec 2.99, deprecates the removed syntax as an aid to upgrading to RSpec 3.

As with all tags with version numbers, please use this tag only for questions which are actually specific to RSpec 3, and always tag such questions with the non-versioned tag as well as with this tag.

381 questions
117
votes
1 answer

rspec 3 - stub a class method

I am upgrading from rspec 2.99 to rspec 3.0.3 and have converted instance methods to use allow_any_instance_of, but haven't figured out how to stub a class method. I have code like this: module MyMod class Utils def self.find_x(myarg) #…
Peter Sankauskas
  • 2,882
  • 4
  • 27
  • 28
100
votes
2 answers

How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it?

I am doing the Rails Tutorial for the second time. When I enter this rails generate integration_test static_pages I get spec/rails_helper.rb and spec/spec_helper.rb instead of just spec/spec_helper.rb Now when I run my tests, they are longer (more…
user3417583
  • 1,417
  • 3
  • 11
  • 13
68
votes
1 answer

RSpec allow/expect vs just expect/and_return

In RSpec, specifically version >= 3, is there any difference between: Using allow to set up message expectations with parameters that return test doubles, and then using expect to make an assertion on the returned test doubles Just using expect to…
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
49
votes
2 answers

expected true to respond to true?

I upgraded my rspec-rails to 3.0.1 and now I'm seeing this error on all of my tests Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` I can't find the solution nor what I'm missing.
Luiz E.
  • 6,769
  • 10
  • 58
  • 98
34
votes
3 answers

In RSpec, using let variable inside before :all block

I have the following code inside most of my tests: describe 'index' let(:company) { FactoryGirl.create(:company) } let(:user) { FactoryGirl.create(:user, company: company) } before do sign_in user visit products_path end ... end But I'm…
Fabian Silva
  • 705
  • 1
  • 7
  • 14
30
votes
1 answer

Rspec to have(n).items undefined method

I'm trying to follow a guide on code.tuts and I keep getting an error. Here is my Library spec: require 'spec_helper' describe Library do before :all do lib_arr = [ Book.new("JavaScript: The Good Parts", "Douglas Crockford",…
MikaAK
  • 2,334
  • 6
  • 26
  • 53
29
votes
1 answer

not_to change.by() is not supported

I upgraded rspec version from 2 to 3. This is one of the issues I faced: Failures: 1) Slide after .destroy(force: false) visible if .with_deleted Failure/Error: expect{@slide.destroy(force: false)}.to_not change(Slide.with_deleted,…
pawel7318
  • 3,383
  • 2
  • 28
  • 44
28
votes
1 answer

rspec failing error: expected false to respond to `false?`

I am running this portion of a test: describe Dictionary do before do @d = Dictionary.new end it 'can check whether a given keyword exists' do @d.include?('fish').should be_false end With this code: class Dictionary …
user3417583
  • 1,417
  • 3
  • 11
  • 13
26
votes
1 answer

How to set a value in the params hash when testing a Rails helper method with RSpec?

In Ruby on Rails 4, with RSpec 3.1, how do I set the values of the params hash when testing a Rails helper method? I want to set params[:search] = 'my keyword search' for use in my helper method and then call it from within the it example…
sealocal
  • 10,897
  • 3
  • 37
  • 50
25
votes
5 answers

Set header in RSpec 3 request

I'm trying to set the header for some RSpec requests that require authentication. The header is ACCESS_TOKEN. No matter how I attempt to set the header, it never gets set. I know the app works because I can manually test it, I just cant get rspec…
lightswitch05
  • 9,058
  • 7
  • 52
  • 75
23
votes
1 answer

Is it possible to have parameterized specs in RSpec?

If I have a spec that needs to be run with different values to have it drive a real implementation and not a naive one. An example: it "should return 'fizz' for multiples of three" do @fizzbuzz.get_value(3).should == "fizz" end So far I haven't…
maz
  • 2,466
  • 1
  • 25
  • 32
23
votes
1 answer

How do I unstub in rspec 3 without enabling the old syntax?

I am upgrading from rspec 2 to rspec 3 and would like to use the new syntax and not enable the old syntax. But I have a few stubs that I set up in my top-level before(:each) block that I selectively unstub where I want the original implementation.…
Kevin Bullaughey
  • 2,556
  • 25
  • 37
21
votes
1 answer

What is the difference between "be_true" and "be true" in RSpec

Can any one please explain me about the difference between be_true and be true in Ruby with simple example. I have also seen be_true and be_false are changed to be_truthy and be_falsey I have an example where 'be true' worked, but when I tried to…
Dev Raj
  • 650
  • 2
  • 7
  • 18
19
votes
3 answers

Testing Rake in Rails: Multiple Error Raises Silenced In Test

I have a rake task that guards against dangerous Rails rake rasks, based on the environment. It works fine. When I test each individual dangerous method in RSpec, the test passes. When I test multiple in a row, for multiple environments, the test…
steel
  • 11,883
  • 7
  • 72
  • 109
18
votes
2 answers

How to raise an exception in an RSpec test

I'm stuck on a test scenario. I have a controller method: def update @object = Object.find params[:id] # some other stuff @object.save rescue ActiveRecord::StaleObjectError # woo other stuff end The first part I test with: context…
rob
  • 2,136
  • 8
  • 29
  • 37
1
2 3
25 26