rspec

Disable render when testing a controller

Hi, I'm using Test::Unit with shoulda to test a controller. Since I'm just testing the controller I dont wanna the view to be rendered. I'm stubbing some objects, some errors are throw when the view is rendered, but the test shouldn't fail, because the controller is correct. So, theres any way to disable the rendering of a template/v...

Way to specing simple model method

Right now I have a model function that is something like this: Class Address def first_line "#{self.building_name} #{self.street_name} #{self.suburb}".squeeze(" ").strip end end My address factory is define like this: Factory.define :address do |f| f.building_name "Alpha" f.street_name "Bravo St" f.suburb "Charlie" end ...

Can 'cucumber' run my rspec-on-rails tests?

I have a small test project that I'm using to test the waters for a much larger project. I am using rspec on rails for testing, but recently looked into Cucumber. It looks very nice, but I'm wondering if there's a way for cucumber to run my spec tests, or for rspec (autospec) to run my cucumber features. I've looked around extensively...

Rails RR Framework: multiple calls for instance_of

I would like write RSpec for my controller using RR. I wrote following code: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe RegistrationController do it "should work" do #deploy and approve are member functions stub.instance_of(Registration).approve { true } stub.instance_of...

Generating Missing Spec Files for RSpec

Is there any command available for generating all missing spec files for existing models / controllers? I have a project that has several models that have been generated with out spec files. ...

rails script/generate skip unnecessary files by default

script/generate became very annoying since i started using rspec etc. i dont need unit test files and fixtures anymore, but script/generate makes them anyway. is it possible to set --skip-fixtures and --skip-test to be default system-wide (or at least project-wide)? ...

rake spec not using the rails environment

I'm attempting to use rspec in a rails project I've just upgraded to rails 2.3.2. I've installed rspec 1.2.6 and rspec-rails 1.2.6 as plugins in the app. My problem is the specs don't have access to my app classes or any of the rails standard libraries. First I had to specify the model class I want to test by using the full path from R...

Testing GET in a rails controller

I have a feeling I'm just doing something wrong syntactically but it's surprisingly difficult to Google "GET" so I was hoping someone here might know the answer to this. I'm trying to test a Rails controller from an RSpec test. I'm following an example I found here - http://www.elevatedrails.com/articles/2007/09/10/testing-controllers-...

Why can't I access the controller object in RSpec when testing a controller?

I'm using rspec-rails, version 1.2.6. In a controller test describe WebsController do ... I don't seem to have access to the controller object in order to stub methods. For example, the following won't work: before :all do @feed = mock_model(Feed) controller.should_receive(:feed_from_params).and_return @feed end I g...

Specing a manual call to valid?

Hey all, I am completely lost on this one. I found a code snippet online to help validate fields via ajax as the user types into them. So I'm trying to write a spec against part of it and I just can't get it to pass. Here's the code def validate field = params[:field] user = User.new(field => params[:value]) output = "" user...

Getting RSpec into RDoc

In Ioke doc, the ISpec tests are included in the documentation, see ioke.org/dok/index.html How can this be done with Ruby's RSpec and RDoc (or SDoc)? I can't find any commandline switches or external libs to do so. Any ideas (not including implementing it all by myself ;-) )? ...

Bypassing validation with machinist

Hi, I am writing my specs on my model Thing which has a date field which should be after the date of creation, thus I use the *validate_timeliness* plugin like that validate_date :date, :after Time.now I want to be able to add some Things with an anterior date but validation fails. I want to bypass the validation when creating some T...

When validating ActiveRecord, I'm getting valid? => false but no errors in errors.count. How come?

When creating an ActiveRecord in rspec, I use fixtures for valid records. But when using the fxitures in tests, they seem to fail validation. In the following example, the employee seems to be perfectly valid, and yet the associated validation in the spec says they are invalid. class Employee < ActiveRecord::Base validates_presence_o...

Rspec redirect_to routes are failing expectations (or misparsed?), how come?

It seems my rspec route for :controller => 'phones', :action => 'edit' works...it should be 'phones/123/edit', and IS according to rspec tests and rake routes. But when I create a redirect_to expectation, the expectation fails. Here's the routes test for the url: it "maps #edit" do route_for(:controller => "phones", :action ...

Rspec integration tests without cucumber?

Is there a way to do integration tests with Rspec without using Cucumber? I prefer using just plain old Webrat. Thanks. ...

Running RSpec with Ruby 1.9.1/Rails 2.3.2

Hi all, I've been trying to get RSpec running under Ruby 1.9, and my tests just aren't running. Here's my trace: matt@matt-desktop:~/Development/my_app$ sudo rake spec --trace (in /home/matt/Development/my_app) ** Invoke spec (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** I...

Adding rspec test for library module doesn't seem to pickup Expectations and Matchers

I'm adding more rspec testing to my app and would like to test a ScoringMethods module, which is in /lib/scoring_methods.rb. So I added a /spec/lib directory and added scoring_methods_spec.rb there. I required spec_helper and set up the describe block as so: require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') descri...

Rails, RSpec and Webrat: Expected output matches rendered output but still getting error in view spec

Hello all, I've just gotten started using BDD with RSpec/Cucumber/Webrat and Rails and I've run into some frustration trying to get my view spec to pass. First of all, I am running Ruby 1.9.1p129 with Rails 2.3.2, RSpec and RSpec-Rails 1.2.6, Cucumber 0.3.11, and Webrat 0.4.4. Here is the code relevant to my question config/routes.rb...

How can I use mock models in AuthLogic controller specs?

I am trying to write specs for a controller without using fixtures (instead employing mock models). This controller requires a user to be logged in, for which I'm employing AuthLogic, following the author's recommendations. describe UsersController do def mock_user(stubs={}) @mock_user ||= mock_model(User, stubs) end context...

Using cucumber and Rspec to develop a SOAP client with BDD

As a learning experience I'm developing a small Rails application that is supposed to query an existing SOAP API/web service (using the handsoap gem) and will simply present the information gathered there to a user. I like using rspec and am getting used to cucumber for testing my applications. The part that has me stumped is how to tes...