Why does "ruby <spec_file>" work, but "rake spec" give spec errors?


#1

Hi,

Does anyone know why I would have some spec’s failing when using
“./script/autospec” or “rake spec”, however when I just run them using
“ruby
" it passes ok”? What’s the difference in kicking off a
spec by
these different means?

Only thing that comes to mind is perhaps using "ruby " is
maybe
working in the development environment not the test environment?
However I
have tried running “rake db:migrate RAILS_ENV=test”, as well as doing a
“rake db:test:purge” and then “rake db:test:prepare”…

Thanks


#2

On Tue, Dec 23, 2008 at 8:29 PM, Greg H.
removed_email_address@domain.invalid wrote:

Hi,

Does anyone know why I would have some spec’s failing when using
“./script/autospec” or “rake spec”, however when I just run them using “ruby
" it passes ok”? What’s the difference in kicking off a spec by
these different means?

This is typically due to some accidental dependencies between examples.

What sorts of failures are you getting?


#3

PS. I do call the method in a before(:each)…


describe Recurring, ‘.add_projections (interest)’ do
include RecurringSpecHelper

before(:each) do
load_bank_account_base_fixtures # <=== Called Here
@destn_bank.should_not be_nil
.
.
.

On Wed, Dec 24, 2008 at 11:54 AM, Greg H. <


#4

PSS. Note sure why, however now it seems “rake spec” is working. Did
make
some minor changes to the spec but nothing I would have thought that
would
have solved this…ummm

On Wed, Dec 24, 2008 at 11:56 AM, Greg H. <


#5

On Tue, Dec 23, 2008 at 10:53 PM, Greg H.
removed_email_address@domain.invalid wrote:

PSS. Note sure why, however now it seems “rake spec” is working. Did make
some minor changes to the spec but nothing I would have thought that would
have solved this…ummm

What changes?


#6

actually I didn’t check in so I can’t do a diff :frowning:

I did move the creation of the row in “interest_rates” from the helper
to
the example setup, i.e. this bit:
InterestRate.create!(:rate => 5.0, :start_date =>
Time.now.to_date.years_ago(1), :bank_account_id => @destn_bank.id)

but I’m not sure how this would have changed anything. Next time I get
this
situation I’ll have to note what I change. Sure there is no cache or
state
anywhere in the “spec” mechanics?


#7

Hi,

Here’s an example (below) of the errors I get when I run “rake spec”,
however they don’t occur when I run "spec ". The issue seems
to
be that when I call a help method which is “included” there is a point
it
adds an interest rate row to a table. In the successful case it appears
this works, but in the unsuccessful case it seems the row didn’t get
created.

Doesn’t rspec clean out the database between each test? (i.e. like for
each: it “should do X”) Just trying to understand how things could
clash?

‘Recurring.add_projections (interest) should raise exception if
recurring
items specifies person_id how-ever amount fields are invalid’ FAILED
expected: 8.0,
got: nil (using ==)
./spec/models/recurring/projections_spec.rb:330:

‘Recurring.add_projections (interest) should put allocation in place
when
recurring item specifies person_id & amount fields valid’ FAILED
expected: 8.0,
got: nil (using ==)
./spec/models/recurring/projections_spec.rb:330:

def load_bank_account_base_fixtures
lambda {BankAccount.delete_all}.should_not raise_error
@destn_bank = BankAccount.new(:name => “Bank_Destn”, :active =>
true)
@destn_bank.save!
ir = InterestRate.new(:rate => 8.0, # <== SEEMS THIS ISN’T
THERE
FOR UNSUCCESSFUL CASE
:start_date => Time.now.to_date.years_ago(1),
:bank_account_id => @destn_bank.id
)
ir.save!
end

thanks