views:

42

answers:

2

I have generated some scaffolding for my rails app.

I am running the generated tests and they are failing.

for example

  test "should create area" do
    assert_difference('Area.count') do
      post :create, :area => { :name => 'area1' }
    end

    assert_redirected_to area_path(assigns(:area))
  end

This test is failing saying that :

1) Failure: test_should_create_area(AreasControllerTest) [/test/functional/areas_controller_test.rb:16]: "Area.count" didn't change by 1. <3> expected but was <2>.

There is only one field in the model : name. I am populating this so it cant be because I am failing to populate the only field.

I can run the site and create an area with the name 'area1'. So reality is succeeding, but the test is failing.

I cant ask why its failing, because Im sure theres not enough information here for anyone here to know why. Im just stuck at knowing what avenues to go down to work out why the test is failing. Even putting puts into the code dont print out...

What steps can I take to track this down?

+1  A: 

@request and @response are also useful objects to look at (i.e. puts @response inside your test). I don't know what authentication you are using, but check RAILS_ROOT/lib for authenticated_test_helper, or the /lib, or /test of your authentication gem. You'll find methods for performing a login.

+1  A: 

Per the request above, and matching what I was expecting that you'd find when you dug into your logs, you have an authorization that isn't being met in your test.

jdl