updated Diff::Display lib
[gitorious:yousource.git] / vendor / diff-display / spec / generator_spec.rb
1 require File.dirname(__FILE__) + '/spec_helper.rb'
2
3 describe Diff::Display::Unified::Generator do
4   
5   before(:each) do
6     @generator = Diff::Display::Unified::Generator.new
7   end
8   
9   it "Generator.run raises if doesn't get a Enumerable object" do
10     proc {
11       Diff::Display::Unified::Generator.run(nil)
12     }.should raise_error(ArgumentError)
13   end
14   
15   it "Generator.run processes each line in the diff" do
16     Diff::Display::Unified::Generator.expects(:new).returns(@generator)
17     @generator.expects(:process).with("foo")
18     @generator.expects(:process).with("bar")
19     Diff::Display::Unified::Generator.run("foo\nbar")
20   end
21   
22   it "Generator.run returns the data" do
23     Diff::Display::Unified::Generator.expects(:new).returns(@generator)
24     generated = Diff::Display::Unified::Generator.run("foo\nbar")
25     generated.should be_instance_of(Diff::Display::Data)
26   end
27   
28   it "the returned that object is in parity with the diff" do
29     %w[simple only_add  only_rem multiple_adds_after_rem].each do |diff|
30       data = Diff::Display::Unified::Generator.run(load_diff(diff))
31       data.to_diff.should == load_diff(diff).chomp
32     end
33   end
34   
35   describe "edgecase bugs" do
36     it "multiple rems and an add is in parity" do
37       diff_data = load_diff("multiple_rems_then_add")
38       data = Diff::Display::Unified::Generator.run(diff_data)
39       #pp data
40       data.to_diff.should == diff_data.chomp
41     end
42     
43   end
44   
45 end