Oh, I guess it makes sense that it wouldn't work there. The stuff in test.rb is run as part of the initializer block, meaning that Rails hasn't been set up yet there. I would just stick it all in spec_helper.rb. That's what I do and was my initial instinct, because it keeps all the test setup in one place. And it looks like it's by far the easiest way, too :)
Pat "Greg Hauptmann" <[EMAIL PROTECTED]> writes: > how to I get a model statement to run within "test.rb" by the way? > For example to get the following to run: > > RecurringType.create(:name => "TYPE_BASIC") > > If I just stick this in I get: > > --------------------extract------------------ > Macintosh-2:myequity greg$ rake spec > (in /Users/greg/source/myequity) > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:265:in > `retrieve_connection': ActiveRecord::ConnectionNotEstablished > (ActiveRecord::ConnectionNotEstablished) > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in > `connection' > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:1149:in > `columns' > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2616:in > `attributes_from_column_definition_without_lock' > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/locking/optimistic.rb:55:in > `attributes_from_column_definition' > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2137:in > `initialize' > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in > `new' > from > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:642:in > `create' > from /Users/greg/source/myequity/config/environments/test.rb:24:in > `load_environment' > ... 14 levels... > from > /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/example_group_runner.rb:13:in > `load_files' > from > /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/options.rb:98:in > `run_examples' > from > /Users/greg/source/myequity/vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in > `run' > from /Users/greg/source/myequity/vendor/plugins/rspec/bin/spec:4 > rake aborted! > Command /opt/local/bin/ruby > -I"/Users/greg/source/myequity/vendor/plugins/rspec/lib" > "/Users/greg/source/myequity/vendor/plugins/rspec/bin/spec" > "spec/lib/hash_extensions_spec.rb" "spec/models/bank_account_spec.rb" > "spec/models/frequency_spec.rb" "spec/models/interest_rate_spec.rb" > "spec/models/projections/projections_spec.rb" > "spec/models/recurring_spec.rb" "spec/models/recurring_type_spec.rb" > "spec/models/transaction_spec.rb" --options > "/Users/greg/source/myequity/spec/spec.opts" failed > -------------------------- > > > On Thu, Nov 6, 2008 at 5:45 AM, Pat Maddox <[EMAIL PROTECTED]> wrote: >> "Mark Wilden" <[EMAIL PROTECTED]> writes: >> >>> I'll just point out one more disadvantage of assuming the contents of the >>> test database are >>> correct (without 'rake db:test:prepare'). If you interrupt a test with >>> Ctrl-C (especially when >>> running autospec), it's possible for the transaction not to get rolled >>> back. An uncommitted >>> transaction should get rolled back automatically, but I've seen that fail >>> to happen, at least >>> with PostgreSQL 8.1. A test would assume that a given table is empty, >>> they'd add a row, expect >>> the count to be 1, and it would fail because of existing cruft. I >>> eventually learned to run >>> 'rake spec' when weird failures happened. Just something to keep in mind. >> >> Well that is fascinating. It seems very, very wrong. Something I might >> expect from MySQL, but never postgres... :) >> >> Pat >> _______________________________________________ >> rspec-users mailing list >> [email protected] >> http://rubyforge.org/mailman/listinfo/rspec-users >> > _______________________________________________ > rspec-users mailing list > [email protected] > http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________ rspec-users mailing list [email protected] http://rubyforge.org/mailman/listinfo/rspec-users
