Created
November 6, 2010 12:47
-
-
Save dtchepak/665388 to your computer and use it in GitHub Desktop.
Fixed undefined local variable or method `docs' for #<DocsToCode:0x358cb30> by closing over local vars
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 'spec' | |
class DocsToCode | |
def docs_in(path) | |
[] | |
end | |
def code_in(doc) | |
"" | |
end | |
def extract(path) | |
code = [] | |
docs_in(path).each { |doc| code << code_in(doc) } | |
code | |
end | |
end | |
describe DocsToCode do | |
describe "when convertings docs to code" do | |
docs = ["first doc", "second doc"] | |
samples = ["first sample", "second sample"] | |
subject do | |
sut = DocsToCode.new | |
metaclass = class << sut; self; end | |
metaclass.send(:define_method, :docs_in) { |path| docs } | |
metaclass.send(:define_method, :code_in) do |doc| | |
return samples[0] if doc == docs[0] | |
return samples[1] if doc == docs[1] | |
end | |
sut | |
end | |
it "should extract code sample from each doc" do | |
subject.extract("a path").should == samples | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment