shoulda

uninitialized constant Test::Unit::TestResult::TestResultFailureSupport

I get the error in subj when I'm trying to run specs or generators in a fresh rails project. This happens when I add shoulda to the mix. I added the following in the config/environment.rb: config.gem 'rspec', :version => '1.2.6', :lib => false config.gem 'rspec-rails', :version => '1.2.6', :lib => false config.gem "thoughtbot-shoulda"...

Test::Unit tests passing on OS X, erroring out on CentOS

I have a set of Test::Unit tests for a Rails application. It was developed on OS X under Ruby 1.8.6, Rails 2.3.4. I'm also using thoughtbot-shoulda 2.10.2. I'm using standard Rails fixtures, not factories. I've checked out the project onto a CentOS Linux 5 workstation for another developer to work on. He's running Ruby 1.8.7. (The ap...

What test framework should I use to test my Rails model?

With the many testing framework that is available in the Ruby community namely: unittest, rspec, shoulda, and coulda, what would be the most appropriate testing framework to test my Rails model? Do they basically have the same functionality, which is to unittest my model? When should I use which? What is the advantage of using one and ...

BDD on Rails - Is the community more behind Shoulda or RSpec?

For a new application I want to start dabbling in BDD and I'm trying to decide between using RSpec or Thoughtbot's Shoulda. I like the macros that Shoulda uses, and the fact that it doesn't seem to reinvent the way Ruby/Rails does testing, but simply provides an add-on. On the other hand, the macros seem like a bit too much "magic" ins...

Custom test runner for Ruby (and shoulda)

I want to modify the test runner when using Ruby and shoulda. The standard runner produces output like this: .... Finished in 0.009167 seconds 4 examples, 0 failures As a starting point, I'd like to be able to modify this. Later, I want to create custom HTML output. How do I get started on this? I've done a lot of googling, but can...

How to run a single shoulda context test in ruby Test::Unit framework

I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test": ruby functional/user_controller_test.rb -n delete_user_test Now when I'm using the shoulda plugin with Test::Unit I try to use the same technique as follows: ... context "Deleting a User" do should "remove user ...

Shoulda + FactoryGirl: Can I make my tests faster?

I'm looking for a way to speed up my Shoulda + FactoryGirl tests. The model I'm trying to test (StudentExam) has associations to other models. These associated objects must exist before I can create a StudentExam. For that reason, they are created in setup. However, one of our models (School) takes significant time to create. Becaus...

Should I mock my model in rails controller tests?

I am finding holes in my coverage because I have been mocking my models in controller examples. When I remove a model's method upon which a controller depends, I do not get a failure. Coming from TDD in statically typed languages, I would always mock dependencies to the object under test that hit the database to increase speed. I would...

Shoulda tests failing on model with no id

I created a new model in my rails app. Since it's a one-to-one relation with another table, there's no need for the new model to have an id column. Everything is working fine, but for some reason, all of my Shoulda tests on this model are failing. For example: should_validate_presence_of :first_name is throwing this error: ActiveR...

Shoulda: Test validates_presence_of :on => :update

I'm using Shoulda in combination with Test::Unit on one of the projects I work on. The issue I'm running into is that I recently changed this: class MyModel < ActiveRecord::Base validates_presence_of :attribute_one, :attribute_two end to this: class MyModel < ActiveRecord::Base validates_presence_of :attribute_one validates_pr...

How do I mix nested resources with multiple post values when testing Rails controllers?

I have a model called "Post" which is a nested resource under a model called "Project" and I'm trying to test the controller. The code works find in my browser, but I can't get it to work in the test. Here's the test context "on POST to :edit" do setup do post( :edit, :project_id => @project1.to_param, :id => @post1...

ActiveSupport::TestCase vs Test::Unit::TestCase when unit testing rails

I recently noticed my test database is not being cleaned up after my tests run if my tests subclass Test::Unit::TestCase. If my tests subclass ActiveSupport::TestCase, everything is cleaned up properly. Can anyone explain why, and/or provide an explanation of using one versus the other? I am using shoulda and factory_girl. Thanks. ...

In Rails controller tests, Is there a way to simulate a specific remote IP?

Some functionality in my app works differently depending on the client's IP address. Is there a way to test that in Rails functional tests? I'm using Test::Unit and Shoulda. ...

Print a List of All Tests in a Rails App

Is there an easy ruby or rails command to get a list of all the tests in an application? I use Shoulda primarily, but if there's a ruby solution regardless of test suite that would work too. ...

How to unit test delete operation on a bunch of records using flexmock

I am using rails 2.3.5 and here is the main action in my controller. @klass.paginated_each(:conditions => @cond ) do |record| klass.send(:delete, record) end Here is my functional test with shoulda and flexmock context 'xhr advance_search with delete_all action' do setup do flexmock(Article).new_instances.should_receive(:de...

Where should I place universal setup code for rails unit tests?

I would like to stub a web service proxy before all my unit tests. I could call some shared code in each unit test, but I was wondering if there is a better way. I am using Shoulda. Thanks ...

Shoulda on Rails - should render_with_layout deferred

Hi all, I would appreciate if someone could help/explain the following please. I am trying to test a controller with shoulda to see if a correct layout is used. The method should_render_with_layout throws a NoMethodError whilst should render_with_layout passes but says the function is deferred. Any help would be appreciated.. Thanks ...

Authlogic: logging-in twice on the same test

Is there any way to logout and login another user when testing with Authlogic? The following test case just fails class MessagesControllerTest < ActionController::TestCase setup :activate_authlogic should "sender send a message and recipient delete it" do @sender = Factory(:user, :login => 'sender') @recipient = Factory(:u...

Getting access to assertion methods from a Shoulda should method

I have a shoulda macro/method that tests controller responses for XPath conditions like so: def self.should_have_xpath(path, &block) should "have an element matching the path: #{path}" do xml = REXML::Document.new @response.body match = XPath.match(xml, path) if block_given? yield match else assert match.si...

Duplicate Entry errors using Shoulda Macros

I wrote some tests for a several models and controllers of a Rails application using Shoulda macros, but one after another they each fail with the error ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '1' for key 1: INSERT INTO `replies` (`created_at`, `from_user`, `updated_at`, `read`, `text`, `tweeted_at`, `id`, `user_id...