[rspec-users] Test::Unit Functional failure puzzle

James Byrne lists at ruby-forum.com
Thu Nov 20 14:30:17 EST 2008


Not an RSpec question, but I was led to this problem by starting to use
autotest with cucumber and so, however unjustly, I feel that RSpec has
to shoulder some of the blame.

I have a failing test in my clients_controller test and I cannot figure
out what is wrong from the information provided from the test results
and the logs.  I would appreciate it someone here to take a look at this
and show me what I am missing.

The test:

class ClientsControllerTest < ActionController::TestCase

  fixtures  :entities, :clients

  def test_should_create_client
    assert_difference('Client.count') do
      post :create, :client =>  { :entity_id => 1,
           :client_status => 'HOLD',
           :client_credit_policy => 'CASH',
           :client_credit_terms => 0,
           :effective_from => "19841101000000".to_date,
           :superseded_after => "20141031235959".to_date
      }
    end

    assert_redirected_to client_path(assigns(:client))
  end


The model:

class Client < ActiveRecord::Base

  belongs_to                  :entity

  validates_associated
  validates_presence_of       :effective_from
  validate                    :date_range

  private

  def date_range
    unless effective_from
      errors.add_to_base("An Effective date is required") \
    end
    if  superseded_after
      errors.add_to_base("Superseded date falls before Effective date")
\
        if superseded_after < effective_from
    end
  end

end

The test result:

/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb"
"test/functional/clients_controller_test.rb"
"test/functional/entity_client_controller_test.rb"
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
Started
F........
Finished in 1.096921 seconds.

  1) Failure:
test_should_create_client(ClientsControllerTest)
    [/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/active_support/testing/core_ext/test/unit/assertions.rb:51:in
`assert_difference'
     /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.1/lib/action_view/renderable.rb:81:in
`each_with_index'
     /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/active_support/testing/core_ext/test/unit/assertions.rb:47:in
`each'
     /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/active_support/testing/core_ext/test/unit/assertions.rb:47:in
`each_with_index'
     /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/active_support/testing/core_ext/test/unit/assertions.rb:47:in
`assert_difference'
     ./test/functional/clients_controller_test.rb:19:in
`test_should_create_client'
     /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/active_support/testing/setup_and_teardown.rb:60:in
`__send__'
     /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/active_support/testing/setup_and_teardown.rb:60:in
`run']:
<Client.count> was the expression that failed.
<3> expected but was
<2>.

9 tests, 10 assertions, 1 failures, 0 errors
/usr/bin/ruby -Ilib:test
"/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb"
Errors running test:functionals!


So, the test client is not being inserted.  But I do not see in the
test.log any sql that does an INSERT so I am at a loss to explain what
is happening.

The log:

Processing ClientsController#new (for 0.0.0.0 at 2008-11-20 14:21:19)
[GET]
Rendering template within layouts/application
Rendering clients/new
Rendered entities/_entity_header (4.6ms)
Rendered clients/_client_detail (3.5ms)
Rendered shared/_effective_period (3.5ms)
Completed in 28ms (View: 24, DB: 4) | 200 OK
[http://test.host/clients/new]
  Client Load (1.5ms)   SELECT * FROM "clients" WHERE ("clients"."id" =
953125641)


Processing ClientsController#show (for 0.0.0.0 at 2008-11-20 14:21:19)
[GET]
  Parameters: {"id"=>"953125641"}
  Client Load (1.6ms)   SELECT * FROM "clients" WHERE ("clients"."id" =
953125641)
Rendering template within layouts/application
Rendering clients/show
  Entity Load (1.2ms)   SELECT * FROM "entities" WHERE ("entities"."id"
= 1)
Completed in 17ms (View: 10, DB: 8) | 200 OK
[http://test.host/clients/953125641]
  Client Load (1.5ms)   SELECT * FROM "clients" WHERE ("clients"."id" =
953125641)


Processing ClientsController#update (for 0.0.0.0 at 2008-11-20 14:21:20)
[PUT]
  Parameters: {"client"=>{}, "id"=>"953125641"}
  Client Load (1.6ms)   SELECT * FROM "clients" WHERE ("clients"."id" =
953125641)
Redirected to #<Client:0xb71808c8>
Completed in 12ms (DB: 11) | 302 Found
[http://test.host/clients/953125641?]
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list