Forum: RSpec why does "ruby <spec_file>" work, but "rake spec" give spec errors?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-24 02:31
(Received via mailing list)
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
<spec file>" 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 <spec file>" 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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-12-24 02:45
(Received via mailing list)
On Tue, Dec 23, 2008 at 8:29 PM, Greg Hauptmann
<greg.hauptmann.ruby@gmail.com> 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
> <spec file>" 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?
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-24 02:56
(Received via mailing list)
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 <specfile>".   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?


1)
'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:

2)
'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
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-24 02:58
(Received via mailing list)
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 Hauptmann <
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-24 04:59
(Received via mailing list)
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 Hauptmann <
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2008-12-24 05:03
(Received via mailing list)
On Tue, Dec 23, 2008 at 10:53 PM, Greg Hauptmann
<greg.hauptmann.ruby@gmail.com> 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?
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-24 07:41
(Received via mailing list)
actually I didn't check in so I can't do a diff  :(

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?
This topic is locked and can not be replied to.