Skip to content

Instantly share code, notes, and snippets.

@kbarber
Created December 30, 2011 21:26
Show Gist options
  • Save kbarber/1541536 to your computer and use it in GitHub Desktop.
Save kbarber/1541536 to your computer and use it in GitHub Desktop.
mocking mysql database connections
#!/usr/bin/env rspec
require 'mocha'
require 'mysql'
describe "foo" do
it "should mock mysql query" do
mock_mysql = mock("Mysql")
Mysql.expects(:new).returns(mock_mysql)
mock_mysql.expects(:query).with("create database foo")
db = Mysql.new("localhost", "root", "this is not the password")
db.query("create database foo")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment