spec/sugar-high/file/file_spec.rb in sugar-high-0.2.0 vs spec/sugar-high/file/file_spec.rb in sugar-high-0.2.1
- old
+ new
@@ -42,7 +42,44 @@
it "should return all file names of an array of paths to files" do
expr = fixtures_dir + '/*.txt'
Dir.glob(expr).file_names('txt').should == ['empty', 'non-empty']
end
end
+
+ describe '#read_from' do
+ let(:non_empty_file) { fixture_file 'non-empty.txt' }
+
+ it "should read all the content into a block" do
+ File.read_from non_empty_file do |content|
+ content.should match /blip/
+ content.should match /blup/
+ end
+ end
+
+ it "should read all the content before a given marker" do
+ content = File.read_from non_empty_file, :before => 'blap'
+ content.should match /blip/
+ content.should_not match /blap/
+ end
+
+ it "should read all the content after a given marker" do
+ content = File.read_from non_empty_file, :after => 'blap'
+ content.should match /blup/
+ content.should_not match /blap/
+ end
+
+ it "should read all the content before a given marker into a block" do
+ File.read_from non_empty_file, :before => 'blap' do |content|
+ content.should match /blip/
+ content.should_not match /blap/
+ end
+ end
+
+ it "should read all the content after a given marker into a block" do
+ File.read_from non_empty_file, :after => 'blap' do |content|
+ content.should match /blup/
+ content.should_not match /blap/
+ end
+ end
+ end
end