Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created March 15, 2012 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/2042094 to your computer and use it in GitHub Desktop.
Save myronmarston/2042094 to your computer and use it in GitHub Desktop.
source :rubygems
gem 'rspec'
gem 'rspec-fire', git: 'git://github.com/myronmarston/rspec-fire.git', ref: '48d85c5545f338517c400b464b4ab8a4b9daca4a'
gem 'sinatra'
GIT
remote: git://github.com/myronmarston/rspec-fire.git
revision: 48d85c5545f338517c400b464b4ab8a4b9daca4a
ref: 48d85c5545f338517c400b464b4ab8a4b9daca4a
specs:
rspec-fire (0.2.2)
GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.3)
rack (1.4.1)
rack-protection (1.2.0)
rack
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
rspec
rspec-fire!
sinatra
module ShardManager
extend self
def use(host, database)
db = Object.new
yield db
end
end
class Projects
def self.for_user(user_id)
ShardManager.use("localhost", "db_for_user_#{user_id}") do |db|
db[:projects].all
end
end
end
require 'rspec/fire'
describe Projects, ".for_user" do
include RSpec::Fire
it 'queries the correct shard' do
db = { projects: stub(all: %w[ project1 project2 ]) }
shard_manager = fire_replaced_class_double("ShardManager")
shard_manager.should_receive(:use).
with("localhost", "db_for_user_17").and_yield(db)
Projects.for_user(17).should eq(%w[ project1 project2 ])
end
end
➜ rspec_mocks_issue_117 git:(master) ✗ ruby --version
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]
➜ rspec_mocks_issue_117 git:(master) ✗ be rspec issue_spec.rb
.
Finished in 0.00144 seconds
1 example, 0 failures
➜ rspec_mocks_issue_117 git:(master) ✗ be rspec issue_spec.rb -rsinatra
F
Failures:
1) Projects.for_user queries the correct shard
Failure/Error: ShardManager.use("localhost", "db_for_user_#{user_id}") do |db|
NoMethodError:
private method `use' called for ShardManager (fire double):Module
# ./issue_spec.rb:12:in `for_user'
# ./issue_spec.rb:29:in `block (2 levels) in <top (required)>'
Finished in 0.00161 seconds
1 example, 1 failure
Failed examples:
rspec ./issue_spec.rb:23 # Projects.for_user queries the correct shard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment