Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created June 21, 2011 22:51
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 lukeredpath/1039158 to your computer and use it in GitHub Desktop.
Save lukeredpath/1039158 to your computer and use it in GitHub Desktop.
Using Mocha's state machines
class FakeResource # fake RestClient::Resource
attr_reader :path
def initialize(path = "/")
@path = Mocha::Mockery.instance.new_state_machine("location").starts_as(path)
end
def [](path)
tap { @path.become(path) }
end
end
describe "Github::Client" do
before(:each) do
@resource = FakeResource.new
@client = Github::Client.new(@resource)
end
describe "#get" do
it "performs a GET request to /some/path on the resource" do
@resource.expects(:get).when @resource.path.is("/some/path")
@client.get("/some/path")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment