rspec

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 sign_in is really jamming up the works. Any thing will help. ...

Please help me setting up my Rails3 app testing tools

Hello, I'm starting a new rails 3 application, and I want it to be tested the better I can. This application is eavily based on plugins (wich will become gems later). One of this gem will be a proxy which talk with an API and outputs formatted data. Few plugins will process data sent by this proxy My questions : Should I use cucum...

Getting Rails 3 Generators with Rspec 2 and Mocha

I've followed all of the steps that I've been able to find online for configuring Rails 3 with Rspec 2 and Mocha. In my Gemfile: group :development do gem 'rails3-generators' gem "rspec", '>= 2.0.0.beta.19' gem "rspec-rails", '>= 2.0.0.beta.19' end group :test do gem "faker" gem "rspec", '>= 2.0.0.beta.19' gem "rspec-rails"...

How do I silence the delayed_job output in test?

I am using delayed_job for background tasks such as system e-mails and different timed events. I use Delayed::Worker.new.work_off to work off the events in my RSpec tests, but then the test out put gets littered with sh*t like: [Worker(host:ch.local pid:24307)] RPM Monitoring DJ worker host:ch.local pid:24307 [Worker(host:ch.local pid...

How to run an entire rspec group from the command line ?

I can run a single rspec example with spec -e 'should be awesome' spec/models/stuff_spec.rb but how do I run an entire group ? describe 'GoodStuff' do it 'should be awesome' do true.should be_true end it 'want to run this too' do true.should be_true end end I've heard there's a spec -g option, but a) its not docume...

RSpec 1.3 without output

I installed RSpec 2 along RSpec 1.3 and since then I think the spec command runs without executing the test file. I removed RSpec 2 and am using RSpec 1.3 again. I type for example "spec spec/views/messages/show.html.erb_spec.rb" on the commandline and the command returns after a few seconds without output. I added errors to the spec fi...

DRY the SUT up - RSpec and Mocking question

n the .net world, my specs would follow the Arrange, Act, Assert pattern. I'm having trouble replicating that in rspec, because there doesn't appear to be an ability to selectively verify your mocks after the SUT has taken it's action. That, coupled with the fact that EVERY expectation is evaluated at the end of each 'It' block, is cau...

Could not find generator rspec:install.

I'm trying to follow this tutorial here: http://railstutorial.org/chapters/static-pages#top When I run: $ rails generate rspec:install I get: Could not find generator rspec:install. What could be the problem? Provided that I'm using Rails 3.0.0.rc Thanks. ...

How to test a before_save method including accossioations with rspec

Hi there, I'm having a problem testing the following model: class Bill < ActiveRecord::Base belongs_to :consignee before_save :calc_rate def calc_rate self.chargeableweight = self.consignee.destination.rate * self.weight end end The consignee model: class Consignee < ActiveRecord::Base belongs_to :destination has_ma...

How do i test routes in Rails 3 plugins?

I've tried to use the recommended way (from the Rails Guides) to test routes generated in plugins, but the test keeps failing. What's odd is that if I reload the routes AFTER creating the route (or so I think), the test fails, but if I let the test go through once (e.g. using autotest), then the route gets recognized on subsequent attem...

Api documentation for Rspec?

Is there an API documentation for Rspec like the one for Rails? ...

Rspec before method

If a spec file contains this before the it() example groups, what does it mean? context "when almost full (with one element less than capacity)" do before(:each) do @stack = Stack.new (1..9).each { |n| @stack.push n } end end context "when full" do before(:each) do @stack = Stack.new (1..10).each { |n| @stack.push...

Rspec equal method

From what I have understood, the equal method checks if the object is the same. person = Person.create!(:name => "David") Person.find_by_name("David").should equal(person) This should be true. But aren't there two different objects here? How could two objects be the same? I don't understand that. ...

rspec - paperclip not loading attr_accessors

I'm using Rails 2.3.5, paperclip 2.3.3 with rspec and factory_girl. Can't figure out why the attr_accessors are undefined when I try to test upload or simply calling. e.g. account.profile_photo.file? undefined method `profile_photo_file_name' for #Account:0x105970af8 Where I have it running properly in Development. account.rb h...

RVM, Merb, Rake and RSpec

Hello everyone, I am currently running ruby-1.9.1 installed via RVM. I have been looking at using Merb, but when I try and run it I get this error: sam@shiny-dev:~/Projects/mojo$ rake db:migrate (in /home/sam/Projects/mojo) Merb root at: /home/sam/Projects/mojo /home/sam/.rvm/gems/ruby-1.9.1-p378@merb/gems/dm-validations-...

spec rake task for daily cron

I have a series of rspec tests which I use to make sure some web scraping services I wrote are still valid. I have all of these inside a GEM which my rails app requires and I'm not quite sure how to embed a rake task of spec for an external gem? I'm not sure that is at all clear, I have a gem w/rspecs: Gem w/rspecs MyApp I would lik...

RSpec test of Treetop parser output doesn't match when it should.

I have this spec: it 'can parse armies with only section headers' do list = <<-LIST :Core :Special :Omgg :Moarheaders LIST expected_output = "## Core\n## Special\n## Omgg\n## Moarheaders\n" parsed = @parser.parse(list) parsed.should_not be_nil parsed.transform.should be expected_output end Which produces this outpu...

Rails Faking a Route

To be specific, I'm trying to get ActionController::Routing::Routes.recognize_path to recognize a route that is not in routes.rb, for testing purposes. Is it possible to somehow mock or dynamically add a route? I'm using Rspec with Mocha. ...

Not able to create a spec file for the controller in Rails

Hi, I am new to ROR. I am working on Rspec.. I have been provided with a full package of an application. I kept it in my rails dir. The dir itself contains spec folder with some controllers/models and fixtures but without spec_helper file. So when i run $spec spec/ i got an error /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/sp...

rspec expect throws "undefined method"

I am a complete Ruby newby and am playing around with rspec I am testing a class (Account) that has this line: attr_reader :balance When I try to test it with this method: it "should deposit twice" do @acc.deposit(75) expect { @acc.deposit(50) }.to change(Account.balance).to(125) end I get this error: NoMethodError in...