rspec

How would you test observers with rSpec in a Ruby on Rails application?

Suppose you have an ActiveRecord::Observer in one of your Ruby on Rails applications - how do you test this observer with rSpec? ...

Rails, Restful Authentication & RSpec - How to test new models that require authentication

I've created a learning application using Bort, which is a base app that includes Restful Authentication and RSpec. I've got it up and running and added a new object that requires users to be logged in before they can do anything(before_filter :login_required in the controller). [edit: I should also mention that the user has_many of th...

Why is RSpec so slow under Rails?

Whenever I run rspec tests for my Rails application it takes forever and a day of overhead before it actually starts running tests. Why is rspec so slow? Is there a way to speed up Rails' initial load or single out the part of my Rails app I need (e.g. ActiveRecord stuff only) so it doesn't load absolutely everything to run a few tests...

What is the best way of speccing plugins with RSpec?

I'm creating a plugin, and am looking to use RSpec so I can build it using BDD. Is there a recommended method of doing this? ...

Testing rendering of a given layout with RSpec & Rails

Is it possible to test the use of a given layout using RSpec with Rails, for example I'd like a matcher that does the following: response.should use_layout('my_layout_name') I found a use_layout matcher when Googling but it doesn't work as neither the response or controller seem to have a layout property that matcher was looking for. ...

Best place in spec/ for integration responses?

I have some integration points where I want to test various responses - where do you think should I store these artifacts in my spec/ directory of my rails application? ...

How do you run a single test/spec file in RSpec?

I want to be able to run a single spec file's tests for the one file I'm editing, for example. rake spec executes all the specs. My project is not a Rails project, so rake spec:doc doesn't work. Don't know if this matters, but here is my directory structure. ./Rakefile ./lib ./lib/cushion.rb ./lib/cushion ./lib/cushion/doc.rb ./lib/...

RSpec Stories and Specs: When to use what?

So I want to start using RSpec stories, but I am not sure where writing controller, model and view specs fit in. For example, you have the story "Logging in" with "User provides wrong password" scenario, don't you end up testing the same stuff than controller/model specs (response.should render..., user.should be_nil, etc.) So my ques...

Rspec - problems with switching from plugins to gems

When dropping the use of rspec and rspec-rails plugins and switching to the gem versions instead, is there anything extra I have to change in spec_helper.rb or something to make the specs in my app see the change? I can no longer get my specs to run successfully anymore after deleting the plugins and installing the gems (1.1.8). More...

How to test with RSpec a Rails plugin using "link_to" and "current_page?"

I'm writing a Rails plugin that builds up a menu in a view. I'm using link_to to build the link and *current_page?* to set class="active" on the current page. I've included ActionView::Helpers::UrlHelper so I can use link_to. To get current_page? working in the view, I've had to inherit the current class (apparently ActionView::Base) a...

How do I test Rails block helpers with rSpec

In my views I use a helper that takes arbitrary HTML as a block: <% some_block_helper do %> Some arbitrary HTML and ERB variables here. More HTML here. <% end %> My helper does a bunch of things to the passed block of HTML before rendering it back to the view (Markdown and other formatting). I would like to know what are the clean...

How to best write an RSpec custom matcher to test access control in a Rails app

OK, so instead of writing a whole bunch of access control specs, and duplicating them across many of my spec files, I'm looking to create a custom matcher. So instead of this: describe "access control" do it "should prevent access by non-logged-in users" it "should prevent access by normal users" it "should prevent access by edito...

Getting Started with RSpec - Looking for tutorials

I'm looking to get started building a project and want to use RSpec from day one. My Ruby background is limited, however, I do have a good understanding of MVC and the structure within Ruby. In doing some research for books and tutorials, I've found no currently published books, and have found no tutorials that give a good "hello world"...

Practicing BDD with python

Which are the most advanced frameworks and tools there are available for python for practicing Behavior Driven Development? Especially finding similar tools as rspec and mocha for ruby would be great. ...

How can I add multiple should_receive expectations on an object using RSpec?

In my Rails controller, I'm creating multiple instances of the same model class. I want to add some RSpec expectations so I can test that it is creating the correct number with the correct parameters. So, here's what I have in my spec: Bandmate.should_receive(:create).with(:band_id => @band.id, :user_id => @user.id, :position_id => 1...

Should A Custom Method Be Used In The before(:each) Section

I have a method on the model Category called create_main used to create main categories. Should I use this method in the before(:each) section even though the method itself has to be tested, or should the main category be created manually using rails built in functionality. ...

How do you use Ruby/DL? Is this right?

I am trying to write an interface between RSPEC (ruby flavoured BDD) and a Windows application. The application itself is written in an obscure language, but it has a C API to provide access. I've gone with Ruby/DL but am having difficulties getting even the most basic call to a DLL method to work. Here is what I have so far, in a fil...

Creating/Recreating a Migration-generated Record in the Test Database with RSpec

I have a migration in Rails that inserts a record into the database. The Category model depends on this record. Since RSpec clears the database before each example, this record is lost and furthermore never seems to be created since RSpec does not seem to generate the database from migrations. What is the best way to create/recreate thi...

Couldn't find 'rspec' generator

I'm trying to install RSpec as a gem after having it installed as a plugin. I've gone ahead and followed the directions found here http://github.com/dchelimsky/rspec-rails/wikis for the section titled rspec and rspec-rails gems. When I run ruby script/generate rspec, I get the error Couldn't find 'rspec' generator. Do only the plugins...

Using RSpec for iPhone Controllers

I'm finally getting the hang of RSpec after spending a couple of hours over the weekend. Now I'm stuck trying to figure out how to assert that parameters are indeed passed into the controller. I'm following the Bowled over by Ruby/Cocoa example and adapting it for the iPhone SDK. I've done a more detailed writeup of my progress on my blo...