|connection_info = YAML.load_file("config/database.yml")["test"]|
|RSpec.configure do |config||
|config.around do |example||
|describe Coderetreat do|
|describe ".running_today" do|
|it "returns a coderetreat scheduled for today" do|
|coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today|
|Coderetreat.running_today.all.should =~ [coderetreat]|
|it "does not return a coderetreat not scheduled for today" do|
|coderetreat = Coderetreat.create! city: "Chicago", scheduled_on: Date.today.advance(:days => -1)|
|#Some databases get upset if you try to start a new transaction while a transaction is already in play, so running the whole spec suite chokes when rspec is trying to start a transaction. You need to update your spec_helper to rely on active_record_spec_helper to do this for you.|
|#Replace this line|
|config.use_transactional_fixtures = true|
Interesting. If I run "rake", I get the following error:
activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:645:in `async_exec': PG::Error: connection is closed: SELECT tablename (ActiveRecord::StatementInvalid)
which traces back to:
in the active_record_spec_helper.
@coreyhaines Thanks for posting this! Although I'm starting to get spoiled by the near instantaneous feedback and am considering dropping model specs all together. Right now I've got it costing me about 6 seconds to load active record. Is that what you do with mercuryapp?
@rmcastil Yeah, that's the eventual goal. I tend to only want to load active record when I'm dealing with scopes. Those make sense to have the database loaded up.
Two things I've noticed:
Not sure if I'm doing anything wrong. The idea is awesome though.
I love this idea, and I really want to implement it more in my test suites. But I'm having the problem that my ActiveRecord models just have too damn many dependencies, and I have to add so many "requires" at the top of my spec file that I might as well just require
Of course, the obvious solution here is to reduce the number of dependencies. And in some cases this is pretty easy, but it's often not, because a lot of the dependencies are due to my associations.
E.g. say I have an model
If I set up my spec like this:
... then it will fail, because when it tries to load "comment.rb", it hits the line
So I add
Is there something conceptual I'm missing? How do I get around this? Basic Rails associations don't seem like something I should be refactoring out into a separate class or module, and stubbing out the associations feels a bit icky too (plus I'm not entirely sure how to do it anyway.)
Anyone have any pointers?
Sorry, me again. StackOverflow bounty is available to anyone who can help me out with the above question: