Skip to content

Commit

Permalink
Added specs for when text/elements/attrs are removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Nov 28, 2010
1 parent c8015bf commit 633498e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions spec/diff_spec.rb
Expand Up @@ -14,6 +14,10 @@
let(:changed_attr_name) { Nokogiri::XML('<div><p i="1">one</p></div>') }
let(:changed_attr_value) { Nokogiri::XML('<div><p id="2">one</p></div>') }

let(:removed_text) { Nokogiri::XML('<div><p></p>two</div>') }
let(:removed_element) { Nokogiri::XML('<div></div>') }
let(:removed_attr) { Nokogiri::XML('<div><p>one</p></div>') }

it "should add #diff to Nokogiri::XML::Docuemnt" do
doc.should respond_to(:diff)
end
Expand Down Expand Up @@ -140,4 +144,46 @@
changes[2][0].should == ' '
changes[2][1].should == added_attr.at('p/text()')
end

it "should determine when text nodes are removed" do
changes = added_text.at('div').diff(removed_text.at('div')).to_a

changes.length.should == 3

changes[0][0].should == ' '
changes[0][1].should == added_text.at('p')

changes[1][0].should == ' '
changes[1][1].should == added_text.at('div/text()')

changes[2][0].should == '-'
changes[2][1].should == added_text.at('p/text()')
end

it "should determine when elements are removed" do
changes = added_element.at('div').diff(removed_element.at('div')).to_a

changes.length.should == 2

changes[0][0].should == '-'
changes[0][1].should == added_element.at('//p[1]')

changes[1][0].should == '-'
changes[1][1].should == added_element.at('//p[2]')
end

it "should determine when attributes are removed" do
changes = added_attr.at('div').diff(removed_attr.at('div')).to_a

changes.length.should == 3

changes[0][0].should == ' '
changes[0][1].should == added_attr.at('p')

changes[1][0].should == '-'
changes[1][1].should == added_attr.at('p/@id')

changes[2][0].should == ' '
changes[2][1].should == added_attr.at('p/text()')
end
end

0 comments on commit 633498e

Please sign in to comment.