Questions tagged [rspec2]

RSpec 2 is a version of the Behaviour-Driven Development tool for Ruby programmers. Use this tag only for RSpec 2-specific questions, and tag those questions with [rspec] too.

RSpec 2 is a version of the Behaviour-Driven Development tool for Ruby programmers.

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

1156 questions
48
votes
2 answers

How to test ApplicationController method defined also as a helper method?

In my ApplicationController I have a method defined as a helper method: helper_method :some_method_here How do I test ApplicationController in RSpec at all? How do I include/call this helper method when testing my views/helpers? I'm using Rails3…
Mirko
  • 5,207
  • 2
  • 37
  • 33
48
votes
6 answers

Rails - RSpec - Difference between "let" and "let!"

I have read what the RSpec manual says about the difference, but some things are still confusing. Every other source, including "The RSpec Book" only explain about "let", and "The Rails 3 Way" is just as confusing as the manual. I understand that…
Theo Scholiadis
  • 2,316
  • 2
  • 22
  • 33
46
votes
2 answers

Rspec: expect vs expect with block - what's the difference?

Just learning rspec syntax and I noticed that this code works: context "given a bad list of players" do let(:bad_players) { {} } it "fails to create given a bad player list" do expect{ Team.new("Random", bad_players) }.to…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
46
votes
7 answers

POSTing raw JSON data with Rails 3.2.11 and RSpec

In order to ensure that my application is not vulnerable to this exploit, I am trying to create a controller test in RSpec to cover it. In order to do so, I need to be able to post raw JSON, but I haven't seemed to find a way to do that. In doing…
Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
44
votes
6 answers

How to ignore or skip a test method using RSpec?

please guide how to disable one of the below test methods using RSpec. I am using Selenuim WebDriver + RSpec combinations to run tests. require 'rspec' require 'selenium-webdriver' describe 'Automation System' do before(:each) do ### …
Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125
43
votes
7 answers

Turn off transactional fixtures for one spec with RSpec 2

How do I turn off transactional fixtures for only one spec (or Steak scenario) with RSpec 2? I tried some things found on the web without any success. This leads to an undefined method exception. describe "MyClass without transactional fixtures"…
medihack
  • 16,045
  • 21
  • 90
  • 134
42
votes
3 answers

Using implicit `subject` with `expect` in RSpec-2.11

With the new expect syntax in rspec-2.11, how is it possible to use the implicit subject? Is there a better way than explicitly referencing subject, like below? describe User do it 'is valid' do expect(subject).to be_valid # <<< can…
Hosam Aly
  • 41,555
  • 36
  • 141
  • 182
40
votes
6 answers

Upgrading to devise 3.1 => getting Reset password token is invalid

Solution Thanks to this gist form Steven Harman, I got it working. devise_mail_helpers.rb module Features module MailHelpers def last_email ActionMailer::Base.deliveries[0] end # Can be used like: # …
Andreas Lyngstad
  • 4,887
  • 2
  • 36
  • 69
39
votes
4 answers

How can I stub find_each for rspec testing in rails 3

I was wondering how to test a find_each call in rspec. I'm used to simply stubbing what I want my models to return so I don't rely on test data in the db like this: MyClass.stub(:find).and_return(my_mock) However, in another class I'm doing…
Aaron
  • 13,349
  • 11
  • 66
  • 105
38
votes
1 answer

How to pass an instance variable to an RSpec shared example

I'm using RSpec (2.10.1) to test validations on a model and have extracted some code to share with other model validations. The validations were first written on the Companies table, so the code looks like this: #…
George Shaw
  • 1,771
  • 1
  • 18
  • 32
36
votes
3 answers

mock Rails.env.development? using rspec

I am writing a unit test using rspec. I would like to mock Rails.env.develepment? to return true. How could I achieve this?. I tried this Rails.env.stub(:development?, nil).and_return(true) it throws this…
ssinganamalla
  • 1,250
  • 3
  • 12
  • 19
36
votes
4 answers

RSpec: Stub private method

I try to test a class with RSpec2, that has some private methods, which are called from some public methods. I test the public methods with @foo.should_receive(:start_training).exactly(2).times if they are called and how often. My problem is, that…
23tux
  • 14,104
  • 15
  • 88
  • 187
34
votes
2 answers

Rspec: how can I check if a call to a method of another class is called?

I can I check if FeedItem::populate_from_friend_to_user is called inside the user class? it "should auto populate feed after user.add_friend" do @user.add_friend(@friend1) …
rtacconi
  • 14,317
  • 20
  • 66
  • 84
34
votes
2 answers

Stubbing Devise in rSpec and Rails3

How would you stub Devise in Rails 3 with rSpec. I have a UsersController and a User model. Both of which are associated with Devise at the moment, I'm writing controller specs and I really am having a hard time with my expectations as the Devise…
stuartc
  • 2,244
  • 2
  • 24
  • 31
31
votes
9 answers

"Could not find a valid mapping for #" only on second and successive tests

I'm trying to write a request test that asserts that the proper links appear on the application layout depending in whether a user is logged in or out. FWIW, I'm using Devise for the authentication piece. Here's my spec: require…
Chris Bloom
  • 3,526
  • 1
  • 33
  • 47
1
2
3
77 78