Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[CS] Use subject in specs

  • Loading branch information...
commit ae91af3a4583375dbbf82d5cedb63a623b2ad63a 1 parent 2645575
@benlangfeld authored
Showing with 38 additions and 50 deletions.
  1. +38 −50 spec/niceogiri/core_ext/nokogiri_spec.rb
View
88 spec/niceogiri/core_ext/nokogiri_spec.rb
@@ -3,90 +3,78 @@
describe Nokogiri::XML::Node do
let(:doc) { Nokogiri::XML::Document.new }
+ subject { Nokogiri::XML::Node.new 'foo', doc }
+
it 'aliases #name to #element_name' do
- node = Nokogiri::XML::Node.new 'foo', doc
- node.should respond_to :element_name
- node.element_name.should == node.name
+ subject.should respond_to :element_name
+ subject.element_name.should == subject.name
end
it 'aliases #name= to #element_name=' do
- node = Nokogiri::XML::Node.new 'foo', doc
- node.should respond_to :element_name=
- node.element_name.should == node.name
- node.element_name = 'bar'
- node.element_name.should == 'bar'
+ subject.should respond_to :element_name=
+ subject.element_name.should == subject.name
+ subject.element_name = 'bar'
+ subject.element_name.should == 'bar'
end
it 'allows symbols as hash keys for attributes' do
- attrs = Nokogiri::XML::Node.new('foo', doc)
- attrs['foo'] = 'bar'
-
- attrs['foo'].should == 'bar'
- attrs[:foo].should == 'bar'
+ subject['foo'] = 'bar'
+ subject['foo'].should == 'bar'
+ subject[:foo].should == 'bar'
end
it 'ensures a string is passed to the attribute setter' do
- attrs = Nokogiri::XML::Node.new('foo', doc)
- attrs[:foo] = 1
- attrs[:foo].should == '1'
+ subject[:foo] = 1
+ subject[:foo].should == '1'
- attrs[:some_attr] = :bah
- attrs[:some_attr].should == 'bah'
+ subject[:some_attr] = :bah
+ subject[:some_attr].should == 'bah'
end
it 'joins an array into a string when passed to the attribute setter' do
- attrs = Nokogiri::XML::Node.new('foo', doc)
- attrs[:foo] = 1
- attrs[:foo].should == '1'
+ subject[:foo] = 1
+ subject[:foo].should == '1'
- attrs[:some_attr] = [:bah, :boo]
- attrs[:some_attr].should == 'bahboo'
+ subject[:some_attr] = [:bah, :boo]
+ subject[:some_attr].should == 'bahboo'
end
it 'removes an attribute when set to nil' do
- attrs = Nokogiri::XML::Node.new('foo', doc)
- attrs['foo'] = 'bar'
-
- attrs['foo'].should == 'bar'
- attrs['foo'] = nil
- attrs['foo'].should be_nil
+ subject['foo'] = 'bar'
+ subject['foo'].should == 'bar'
+ subject['foo'] = nil
+ subject['foo'].should be_nil
end
it 'allows attribute values to change' do
- attrs = Nokogiri::XML::Node.new('foo', doc)
- attrs['foo'] = 'bar'
-
- attrs['foo'].should == 'bar'
- attrs['foo'] = 'baz'
- attrs['foo'].should == 'baz'
+ subject['foo'] = 'bar'
+ subject['foo'].should == 'bar'
+ subject['foo'] = 'baz'
+ subject['foo'].should == 'baz'
end
it 'allows symbols as the path in #xpath' do
- node = Nokogiri::XML::Node.new('foo', doc)
- node.should respond_to :find
- doc.root = node
+ subject.should respond_to :find
+ doc.root = subject
doc.xpath(:foo).first.should_not be_nil
doc.xpath(:foo).first.should == doc.xpath('/foo').first
end
it 'allows symbols as namespace names in #xpath' do
- node = Nokogiri::XML::Node.new('foo', doc)
- node.namespace = node.add_namespace('bar', 'baz')
- doc.root = node
- node.xpath('/bar:foo', :bar => 'baz').first.should_not be_nil
+ subject.namespace = subject.add_namespace('bar', 'baz')
+ doc.root = subject
+ subject.xpath('/bar:foo', :bar => 'baz').first.should_not be_nil
end
it 'aliases #xpath to #find' do
- node = Nokogiri::XML::Node.new('foo', doc)
- node.should respond_to :find
- doc.root = node
- node.find('/foo').first.should_not be_nil
+ subject.should respond_to :find
+ doc.root = subject
+ subject.find('/foo').first.should_not be_nil
end
it 'has a helper function #find_first' do
- node = Nokogiri::XML::Node.new('foo', doc)
- node.should respond_to :find
- doc.root = node
- node.find_first('/foo').should == node.find('/foo').first
+ subject.should respond_to :find
+ doc.root = subject
+ subject.find_first('/foo').should == subject.find('/foo').first
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.