rspec

Specifying Content Type in rspec

I'm trying to build an rspec test that sends JSON (or XML) via POST. However, I can't seem to actually get it working: json = {.... data ....}.to_json post '/model1.json',json,{'CONTENT_TYPE'=>'application/json'} and this json = {.... data ....}.to_json post '/model1.json',json,{'Content-Type'=>'application/json'} a...

Testing redirect after login with Devise

I've followed the recommendation from the Devise github pages for this: http://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in Now this works great, but how would you test that you have this behavior now? ...

Rspec Test fail when using FactoryGirl

I am working with FactoryGirl for the first time and have set up my tests for the following controller code # PUT method def chosen answer = Answer.find(params[:id]) if answer.update_attributes({:selected => true}) respond_to do |format| format.html { flash[:notice] = "Success" redirec...

FactoryGirl: How do define a factory without passing parameters

Hello. I'm using Rails 3 / factory_girl_rails / Rspec 2 and Ruby 1.8 I've defined my factories this way: Factory.define :user do |u| u.name 'Some guy' u.sequence(:email) {|n| "person#{n}@example.com" } u.password 'password' end Factory.define :password_reset_user, :parent => :user do |user| user.password_reset_key '...

Testing part of a method with rspec

In this usps ruby gem, how should we write the following address specs: it "should build the HTTP request" # given a hard-coded address it "should parse the XML response" # given a hard-coded response I know how to get the specs to work by breaking the standardize function up into parts, but I don't want to do that because it's unnece...

gem_original_require: no such file to load -- spec/rails

Hi All, I have a rails 2.3.8 app with rspec tests (not written by me, just trying to get them running). When I run "rake spec" I get this error: gem_original_require': no such file to load -- spec/rails (MissingSourceFile) I have the following rspec-related gems installed: rails (2.3.8, 2.3.5) rspec (2.0.1, 1.3.0, 1.2.9, 1.2.4) rsp...

RSpec - generic failure message instead of useful output

This is using RSpec2 - no matter what happens I seem to get the following error when an expectation is not matched. I'm sure (though I cannot try for a while) in version 1 the following code would state that the method 'methods' was not called. The code snippet below demo's this problem - when un-commenting the method in initialize, the...

Autotest not running in Ruby 1.9.2, only 1.8.7

UPDATE: It works now. I truly don't know what happened. I'll leave this Q up for some time, in case other experience the same. If not, I'll soon delete it. TLDR: autotest rspec works with ruby1.8.7 but not in ruby1.9.2. Using rails3, rspec2, autotest 4.4.1. In 1.9.2, it doesn't do anything after starting autotest. OK, now I'm real tire...

Stubbing Chained Queries in Rails 3 and Rspec

I'm trying to test a scope I have that is based upon a chain of other scopes. ("public_stream" below). scope :public, where("entries.privacy = 'public'") scope :completed, where("entries.observation <> '' AND entries.application <> ''") scope :without_user, lambda { |user| where("entries.user_id <> ?", user.id) } scope :public_stream, l...

How do I test logout/signout (UserSessionsController destroy action) when using Authlogic?

I was writing an rspec test for the destroy action of my sessions controller (Authlogic 2.1.6). I can't puzzle out what method I should call, either on the user object or the session object to determine whether the session is still "alive" (that is, that the user is or is not logged in). My first instinct was to use @user.logged_in? bu...