shoulda

Why should I use RSpec or shoulda with Rails?

I am setting up a rails app and I just finished making some unit tests and my friend said that apparently fixtures are no longer cool and people are now using RSpec or shoulda. I was wondering what the actual benefits are to use these other toolkits. Any information at all is appreciated. -fREW ...

How do I remove duplication in shoulda tests?

Here is what I have: context "Create ingredient from string" do context "1 cups butter" do setup do @ingredient = Ingredient.create(:ingredient_string => "1 cups butter") end should "return unit" do assert_equal @ingredient.unit, 'cups' end should "return a...

Shoulda testing workflow from the trenches

Everyone is talking about TDD (BDD) in Rails (and not just Rails) development world today. It's easy to find plenty of good general information about it, there are quite a few tools you can use for this purpose and there are many (good) examples of how to use them. Now, I'm already on the train. I like the idea (never did TDD before) a...

How to properly test this controller action with Shoulda?

I have the following controller action and test. I'm new to testing with Shoulda and I know there are areas of my controller that I can test further. For example, my flash messages as well as verifying the renders. So my question is, how would I properly test this controller action in Shoulda? My controller action (names have been ch...

How to test a named_scope that references a class attribute with Shoulda?

I have the following ActiveRecord classes: class User < ActiveRecord::Base cattr_accessor :current_user has_many :batch_records end class BatchRecord < ActiveRecord::Base belongs_to :user named_scope :current_user, lambda { { :conditions => { :user_id => User.current_user && User.current_user.id } } } end and I'm tryin...

How do you test whether a model has a given method in Rails?

I would like to implement the method User.calculate_hashed_password. I'm trying to use the Shoulda testing library which works with Rails's built-in testing tools, so an answer related to Test::Unit would be just as good as one related to Shoulda (I think). I'm trying to figure out what I need to test and how I should test it. My initia...

Why is this Rails controller test failing?

I'm trying to understand why this test is failing. (I'm kind of new to testing.) I'm using the built-in Rails testing framework with the addition of the Shoulda gem. The test: require 'shoulda' context "on GET to :new" do setup do get(:new) end should_render_template :new should_not_set_the_flash end Fails: 1) Failur...

How do you specify POST params in a Rails test?

Working with Test::Unit and Shoulda. Trying to test Users.create. My understanding is that Rails forms send params for an object like this: user[email] Which turns into hash in your action, right? params[:user][:email] OK, so in my test I've tried... setup { post :create, :post => { 'user[email]' => 'invalid@abc' } } and setup ...

Shoulda: Testing contoller filters

So I have decided to investigate the state of Rails' testing. After reading a few accepted answers here on SO talking about how Rails' testing documentation is atrocious I am starting to agree. Thus far, I am apparently not in the club of people that understand Rails testing- even though I understand the framework quite well, or so I tho...

Is Test::Unit still relevant in rails?

I am learning Rails the age old way. By reading Agile Web Development with Rails (3rd Edition) as a starting point. I am currently in the chapter that teaches Testing. I am also aware of other BDD Testing framework such as RSPec. So I was wondering if frameworks such as RSpec, Cucumber, Shoulda replace the need for knowing/using Test::Un...

Shoulda, Rails Tests , and Autotest

I'm trying to model my tests after the great work that the Thougtbot guys have done. They seem to use the test framework built into Rails Shoulda. Great. I have been hearing a lot about Autotest - that its magical-ness should make things easier.... I expected that things would 'just work' if I installed it. My rake test:units already a...

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...

How to run Rails console in the test environment and load test_helper.rb?

The background: I'm having some problems with Thoughtbot's "Factory Girl" gem, with is used to create objects to use in unit and other tests. I'd like to go to the console and run different Factory Girl calls to check out what's happening. For example, I'd like to go in there are do... >> Factory(:user).inspect I know that you can run...

Setup Factory Girl with Test::Unit and Shoulda

I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on Rails. I have installed the gem, created my factory file under the test/factories directory, and created my spec file under the test/models directory. The current error I'm getting is 'ArgumentError: No such factory: test', which leads me to believe that the test_fa...

testing REST with shoulda and factory_girl - destroy

Hi, i'm developing test for REST using shoulda and factory_girl. Code below context "on :delete to :destroy" do setup do @controller = NewsArticlesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @news_article = Factory.create(:news_article) en...

Code works but test fails

I have a test that's failing even though the operation actually works when I test it in the browser. Something wrong with my test, looks like. I'm using Shoulda and fixtures. require 'test_helper' class AddressesControllerTest < ActionController::TestCase context 'on PUT to :update' do setup do put(:update, { :id...

Using shoulda macros with RSpec

I'm trying to use the shoulda macros within RSpec and am having some problems. I've done the following: spec_helper.rb: require 'shoulda/active_record/macros' Spec::Runner.configure do |config| ... config.include(Shoulda::ActiveRecord::Macros, :type => :model) spec/models/foo_spec.rb: describe Foo do it { should_have_i...

Tests pass using "autotest" but not "rake test" using Authlogic

My tests fail when doing "rake test:functionals" but they pass consistently using autotest. The failing tests in question seems to be related to Authlogic not logging in the user properly when using rake. For facilitating signing in a user in tests, I have a test helper method as follows: class ActionController::TestCase def signin(...

How do I test helper methods using Shoulda and set the params and request values?

I'm using rails 2.2.2 and wondering how can I set the params values to test my helper methods. I found some examples to let you run tests with helper methods but it doesn't work for me when I use the request or params value directly in the method. require 'test_helper' class ProductHelperTest < Test::Unit::TestCase include ProductHe...

What's the main difference between cucumber and shoulda?

How would you make a decision between cucumber and shoulda if you were about to choose a testing framework? What differentiates these two frameworks primarily? ...