Created
March 28, 2012 21:45
-
-
Save mrdanadams/2230855 to your computer and use it in GitHub Desktop.
Testing MongoDB with Mongoid, RSpec, and Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wait_until | |
i = 0 | |
while !(result = yield) and i < 3 do | |
sleep 1 | |
i += 1 | |
end | |
raise "timed out" if !result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment