Skip to content

Instantly share code, notes, and snippets.

@pat
Created March 1, 2012 04:54
Show Gist options
  • Save pat/1947369 to your computer and use it in GitHub Desktop.
Save pat/1947369 to your computer and use it in GitHub Desktop.
Using rspec-fire?
# My normal approach:
require './path/to/my_class'
class OtherClass; end
describe MyClass do
let(:my_class) { MyClass.new }
describe '#add_widget' do
it "makes a widget using OtherClass" do
OtherClass.should_receive(:make_widget!)
my_class.add_widget
end
end
end
# Declaring the OtherClass constant so the test runs by itself. If running in a
# suite, the original OtherClass declaration is picked up, and our one changes
# nothing. But declaring a constant will confuse rspec-fire, right?
@myronmarston
Copy link

@freelancing-god -- I forked this and wrote up how I would do it with rspec-fire with the feature added by my pull request:

https://gist.github.com/1975201

Note that the API (fire_replaced_class_double) is probably not what we'll wind up with, but the basic approach will probably stay. It'd be good to get more input into what the API should be. Please comment on the Pull Request:

xaviershay/rspec-fire#3 (comment)

/cc @xaviershay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment