Created
March 15, 2012 05:22
-
-
Save myronmarston/2042094 to your computer and use it in GitHub Desktop.
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
source :rubygems | |
gem 'rspec' | |
gem 'rspec-fire', git: 'git://github.com/myronmarston/rspec-fire.git', ref: '48d85c5545f338517c400b464b4ab8a4b9daca4a' | |
gem 'sinatra' |
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
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 |
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
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 | |
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_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