rspec

Why doesn't this test in the Diaspora app fail?

From http://github.com/diaspora/diaspora/blob/master/spec/models/profile_spec.rb describe Profile do before do @person = Factory.build(:person) end describe 'requirements' do it "should include a first name" do @person.profile = Factory.build(:profile,:first_name => nil) @person.profile.valid?.should be false ...

User login while testing with rspec and authlogic

I have a spec for testing a controller as below require 'spec_helper' describe ProductsController do setup :activate_authlogic describe "user not logged in" do it "should not GET index" do get :index response.should redirect_to(login_path) end end describe "user logged in" do before(:each) do UserSession.create :username => "rohit...

How to test this ==> rspec + rails

We all know that we have this code in our create action of any basic controller def create if @product.save flash[:notice] = 'Product was successfully created.' redirect_to(products_path) else flash[:notice] = "Data not saved try again" render :action => "new" end end how do we test this part of co...

Can't get RSpec view spec to pass

I've got the following spec in spec/views/users/new.html.erb_spec.rb: require 'spec_helper' describe "users/new.html.erb" do it "displays the text attribute of the message" do render response.should contain("Register") end end But when I run the test it fails with: ActionView::TemplateError in 'users/new.html.erb displ...

Print running spec name

Hi, I have an issue while running my specs for a rails application with rake, it freezes on a certain spec. I would like to see what spec is running. ...

Rspec testing templates being rendered

Im trying to test a condition where on successful signup a Success Template is rendered by the following controller code def create @user = User.new(params[:user]) if @user.save render :template => "success" else flash[:notice] = "Oops Somethings not quite right! :(" render :action => "new" end end ...

Getting the full RSpec test name from within a before(:each) block

RSpec allows you to get the current running test method name in a before(:each) block, by doing the following: Spec::Runner.configure do |config| config.before :each do |x| x.method_name # returns 'should be cool' end end This is for a test like: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe '...

[Rails] Paginate throws error for Custom Validations

I'm attempting to create a custom validation for one of my models in Rails 2.3.5, but I keep recieving the following error everytime I run my testing suite: `method_missing_without_paginate': undefined local variable or method `validates_progression' app/models/project.rb class Project < ActiveRecord::Base ... validates_progres...

Rspec, Spork, & Autotest Error

I'm trying to teach myself rails by going through http://railstutorial.org/. I quit working on the tutorial app last night and then came back to it today. Now I'm getting an error when I start up the Spork server. Here is a trace of the error. spork Using RSpec Loading Spork.prefork block... can't convert nil into Hash (TypeError) /usr/...

How to present a Selenium test written in spec or PHPUnit on Hudson

Hi there, I am setting up Selenium tests on Hudson and looking for an easy way to present nice results such as Project summary and build summary on Hudson. Currently I have written Selenium test cases in Rspec and PHPUnit's extension for Selenium (I prefer working on Rspec over PHP). What is the best way to present detailed report for S...

response.should have_text leads to undefined method `has_text?'

I would like to test a controller that directly renders some JSON output (by using "render :json => @entity_names"). For that task I tried in my spec file "response.should have_text('["enim", "enita"]')". Unfortunately I always get that error: Failure/Error: response.should have_text('["enim", "enita"]') undefined method `has_text?' for ...

Writing spec for controller actions that return XML -- Ruby on Rails

In my controller I have some methods which return json as well as xml data. I need to test those actions. For testing the json part I found this reference and it is working fine. Now I am need of testing the actions for the XML part. Anyone who can help or suggest something are most welcome I've been scratching my head for an hour now bu...

Routes are not available in RSpec integration test

I am following the examples in the Rails Tutorial website and I'm having issues getting the integration tests to work. Specifically the example at listing 8.20 in section 8.4.2 in the tutorial. At the visit signup_path line of code below I get the following error: "undefined local variable or method `signup_path'" require 'spec_helper'...

Getting Rspec + autotest working on windows

I have installed growl + rspec + autotest on my windows 7 machine. From the command prompt, when I type 'rspec spec/' it doesn't work. The tests will only run if I use 'rake spec/' + 'autotest'. Also, I am running these tests: http://railstutorial.org/chapters/static-pages#code:default_pages_controller_spec (i.e. very, very trivial) and...

Objects don't appear in test database when running specs

When saving an object by calling Entity.create(:name => "Entity1") from the Rails console in the testing environment (RAILS_ENV=test rails console) the "Entity1" object correctly appears in the test database (MySQL) when checking it with a mysql client. But when doing the same stuff in an rspec file (entity.create(:name => "Entity1"); sl...

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" do self.use_transactional_fixtures = false ... end This simply does nothing (transac...

Testing JQuery UI autocomplete with Capybara + Env.js does not work (with Selenium it works)

I do an RSpec integration test of the JQuery UI autocomplete functionality by using Capybara. When using Selenium (+ Firefox) as the web driver for Capybara everything works as it should, but when switching to Env.js as driver my tests fail. Are those known shortcomings of Env.js, or do I miss something? ...

How do you test route constraints using RSpec

Given a couple of cities in the DB: City.first.attributes => {:id => 1, :name => 'nyc'} City.last.attributes => {:id => 2, :name => 'boston'} And a route like: match '/:city/*dest' => 'cities#do_something', :constraints => {:city => /#{City.all.map{|c| c.name}.join('|'}/} (so the constraints should evaluate to: /nyc|boston/) And a ...

stubbing factory_girl + rspec methods and attributes

I'm using factory_girl + rspec on Rails 2-3-stable: Test: context "test" do before(:each) do @profile.stub!(:lastfm_enabled?).and_return(true) end it "should be able to scrobble if true" do @profile.update_attribute(:lastfm_scrobbling, true) @profile.lastfm_scrobbling_enabled?.should be_true...

problem to rspec update action using rails 3

I'm facing a problem with rspec and controllers i'm spec'ing an update action, so to do it i call the following code: put :update, :id => "1", :ntp => {:name=>'myservah'} My controller has the following code: def update if @ntp.update_attributes(params[:ntp]) flash.now[:notice] = "Successfully updated ntp." else flash.now[:err...