feedback on File lesson?

1 view
Skip to first unread message

Sarah Allen

unread,
Feb 7, 2010, 12:37:00 AM2/7/10
to test-firs...@googlegroups.com
Hey Alex,

I checked in a first draft of a spec to teach about files. The idea
is that it follows from the previous string and regular expression
lesson where we did markdown to textile conversion. Then in the next
class I plan to teach them how to turn it into a gem! If you have
time, I would love your review:

----------------------------------------------------------
convert_markdown/file_conversion_spec.rb
----------------------------------------------------------
require 'format_independent_textfile'

describe FormatIndependentTextfile do
before do
File.should_not exist "test.text"
File.should_not exist "test.markdown"
File.should_not exist "test.textile"
end

after do
`rm test.*`
end

it "should act like a file" do
fname = "test.text"
FormatIndependentTextfile.open(fname, "w") do |f|
f << "here is some text"
end

File.should exist fname
File.read(fname).should == "here is some text"

end

it "should return textile" do
markdown_file = FormatIndependentTextfile.open("test.markdown", "w
+")

markdown_file << "# this is a heading\n"
markdown_file << "## this is a second level heading\n"

markdown_file.textile

markdown_file.textile.should == <<EOS
h1. this is a heading
h2. this is a second level heading
EOS
end
end


----------------------------------------------------------------------------------------------------
My solution (which makes me want to refactor and change Converter into
a module or something):
(it depends on the previous converter_spec solution which is checked
into the solutions branch)
----------------------------------------------------------------------------------------------------


require 'converter'

class FormatIndependentTextfile < File
def textile
c = Converter.new
self.rewind
c.markdown =self.read
c.textile
end

end


Reply all
Reply to author
Forward
0 new messages