Skip to content

Instantly share code, notes, and snippets.

@mrdanadams
Created March 28, 2012 21:45
Show Gist options
  • Select an option

  • Save mrdanadams/2230855 to your computer and use it in GitHub Desktop.

Select an option

Save mrdanadams/2230855 to your computer and use it in GitHub Desktop.

Revisions

  1. mrdanadams created this gist Mar 28, 2012.
    5 changes: 5 additions & 0 deletions controller_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # do our update
    @controller.record_votes(winner._id.to_s, loser._id.to_s)

    # will this pass or fail? who knows!?
    Item.count(conditions:{ votes:1 }).should == 0
    5 changes: 5 additions & 0 deletions controller_spec2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # do our update
    @controller.record_votes(winner._id.to_s, loser._id.to_s)

    # wait until we get what we want (within reason, of course)
    wait_until { Item.count(conditions:{ votes:1 }) > 0 }
    8 changes: 8 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    RSpec.configure do |config|
    # ...
    config.before(:each) do
    db = Mongoid::Config::master
    # ignore stuff like system.indexes
    db.collection_names.reject {|c| c =~ /^system/}.each {|c| db.drop_collection c}
    end
    # ...
    8 changes: 8 additions & 0 deletions wait_until.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    def wait_until
    i = 0
    while !(result = yield) and i < 3 do
    sleep 1
    i += 1
    end
    raise "timed out" if !result
    end