Skip to content

Instantly share code, notes, and snippets.

@samflores
Created December 2, 2011 17:32
Show Gist options
  • Save samflores/1424100 to your computer and use it in GitHub Desktop.
Save samflores/1424100 to your computer and use it in GitHub Desktop.

Suppose I have a third party lib that uses a DSL to perform its magic like the dsl.rb and runtime.rb files below. My application has a Consumer class that uses that API as shown in the consumer.rb file. How should I spec the say method to ensure the output method receives the correct parameter?

require 'dsl'
class Consumer
def say(message)
DSL.execute do
output message
end
end
end
require 'runtime'
class DSL
def self.execute(&block)
Runtime.new(&block)
end
end
class Runtime
def initialize(&block)
self.instance_eval(&block)
end
def output(message)
puts message
end
end
@rafaelss
Copy link

rafaelss commented Dec 2, 2011

Something like...

Runtime.any_instance.should_receive(:output).with("the message")

@samflores
Copy link
Author

The problem I see in this approach is that I need to know how the API works internally. At least I need to know the execute method creates a Runtime instance. I'm not sure I should dig that deep...

@weldyss
Copy link

weldyss commented Dec 2, 2011

Can you handle the ParamErrorMethod when you pass the param? If so, you can use the ParamError to spec, maybe

If you don't know deeply the API, you can handle only rescues.

@samflores
Copy link
Author

I don't think so :/

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