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
29
votes
6 answers

Unable to stub helper method with rspec

I am trying to stub a method on a helper that is defined in my controller. For example: class ApplicationController < ActionController::Base def current_user @current_user ||= authenticated_user_method end helper_method…
Brad
  • 5,428
  • 1
  • 33
  • 56
28
votes
2 answers

Rspec 2 config :type types

In my spec_helper.rb I have config.include Devise::TestHelpers, :type => :controller so that I can actually test my controllers that require the user to be authenticated. However, the spec for the same class in requests needs to sign in as well or…
Aaron
  • 13,349
  • 11
  • 66
  • 105
28
votes
5 answers

Rspec: setting cookies in a helper test

Helper Method # Determine if this is user's first time def first_time? cookies[:first_time].nil? end Attempted Rspec test it "returns true if the cookie is set" do cookies[:first_time] = "something" helper.first_time?().should…
jmccartie
  • 4,956
  • 8
  • 50
  • 71
27
votes
5 answers

How to test class methods in RSPEC

I wrote a simple class method Buy.get_days(string), and is trying to test it with different text string inputs. However I feel it is very verbose. Is there any more concise way to test the following? Is there a equivalent of subject for methods…
lulalala
  • 17,572
  • 15
  • 110
  • 169
27
votes
4 answers

How to mock request object for rspec helper tests?

I've a view helper method which generates a url by looking at request.domain and request.port_string. module ApplicationHelper def root_with_subdomain(subdomain) subdomain += "." unless subdomain.empty? …
BuddhiP
  • 6,231
  • 5
  • 36
  • 56
25
votes
7 answers

Is there a way to automatically have a "rake db:migrate RAILS_ENV=test" after "rake db:migrate" in development environment?

Is there a way to automatically do a rake db:migrate RAILS_ENV=test after each rake db:migrate when in development environment? I have guard and guard-rspec running, and I am really annoyed about the failing tests, even if it works manually in the…
NobbZ
  • 1,360
  • 3
  • 15
  • 30
25
votes
1 answer

Rails: Good Rspec2 example usage? (Also: Cucumber, Pickle, Capybara)

I'm looking for a rather recent open source application that uses Rspec 2 as test library. I'd like to see how an experienced developer utilizes the library properly to test the full stack, since I'm constantly in doubt concerning my own knowledge…
polarblau
  • 17,649
  • 7
  • 63
  • 84
25
votes
4 answers

RSpec: comparing a hash with string keys against a hash with symbol keys?

Consider the following RSpec snippet: it "should match" do {:a => 1, :b => 2}.should =~ {"a" => 1, "b" => 2} end This test fails because one hash uses symbols for keys and the other uses strings for keys. In my case, one hash is a parsed JSON…
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
24
votes
2 answers

FactoryGirl + RSpec + Rails 3 'undefined method ='

I'm fairly new to rails and TDD (as will no doubt be obvious from my post) and am having a hard time wrapping my brain around Rspec and FactoryGirl. I'm using Rails 3, rspec and factory girl: gem 'rails', '3.0.3' # ... gem 'rspec-rails',…
dearlbry
  • 3,193
  • 2
  • 23
  • 23
24
votes
4 answers

How can I mock super in ruby using rspec?

I am extending an existing library by creating a child class which extends to the library class. In the child class, I was able to test most of functionality in initialize method, but was not able to mock super call. The child class looks like…
John Micalo
  • 241
  • 1
  • 2
  • 3
23
votes
3 answers

How to test attr_accessible fields in RSpec

So we have been setting up attr_accessible and attr_protected on many fields through out our Rails 3.2 app. For now we really don't test to ensure that these fields are protected. So I decided to google some answers and stumbled upon this…
WarmWaffles
  • 531
  • 5
  • 16
23
votes
3 answers

Scope constants to an rspec context

I often want to do context "empty stack" do SOME_CONSTANT = "value" it "should be empty" do # use SOME_CONSTANT end end context "populated stack" do SOME_CONSTANT = "a different value" it "should have some items" do # use…
opsb
  • 29,325
  • 19
  • 89
  • 99
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
21
votes
3 answers

rspec `its` syntax with dynamic conditions

I've been really loving using contexts, subjects and its with rspec to really clean up my test code. Typical example: context "as a user" do subject{ Factory :user } its(:name){ should == "Bob" } end What I can't figure out though is how I…
brad
  • 31,987
  • 28
  • 102
  • 155
21
votes
3 answers

Resetting a singleton instance in Ruby

How do I reset a singleton object in Ruby? I know that one'd never want to do this in real code but what about unit tests? Here's what I am trying to do in an RSpec test - describe MySingleton, "#not_initialised" do it "raises an exception" do …
thegreendroid
  • 3,239
  • 6
  • 31
  • 40
1 2
3
77 78