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?
Created
December 2, 2011 17:32
-
-
Save samflores/1424100 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require 'dsl' | |
| class Consumer | |
| def say(message) | |
| DSL.execute do | |
| output message | |
| end | |
| end | |
| end |
This file contains hidden or 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
| require 'runtime' | |
| class DSL | |
| def self.execute(&block) | |
| Runtime.new(&block) | |
| end | |
| end |
This file contains hidden or 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
| class Runtime | |
| def initialize(&block) | |
| self.instance_eval(&block) | |
| end | |
| def output(message) | |
| puts message | |
| end | |
| end |
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...
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.
Author
I don't think so :/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like...