Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move to RSpec (with Guard)

  • Loading branch information...
commit 4e034f416314f278318a353bec364ce880ed0c26 1 parent d509081
@benlangfeld benlangfeld authored
View
4 .rspec
@@ -0,0 +1,4 @@
+--colour
+--tty
+--format documentation
+--profile
View
5 Gemfile
@@ -2,3 +2,8 @@ source "http://rubygems.org"
# Specify your gem's dependencies in niceogiri.gemspec
gemspec
+
+if RUBY_PLATFORM =~ /darwin/
+ gem 'growl_notify'
+ gem 'rb-fsevent'
+end
View
5 Guardfile
@@ -0,0 +1,5 @@
+guard 'rspec', :version => 2, :cli => '--format documentation' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec/" }
+end
View
19 Rakefile
@@ -1,21 +1,14 @@
require 'rubygems'
+require 'bundler/setup'
require 'rake'
require 'bundler/gem_tasks'
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'spec'
- test.pattern = 'spec/**/*_spec.rb'
- test.verbose = true
-end
+require 'rspec/core'
+require 'rspec/core/rake_task'
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'spec'
- test.pattern = 'spec/**/*_spec.rb'
- test.rcov_opts += ['--exclude \/Library\/Ruby,spec\/', '--xrefs']
- test.verbose = true
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = FileList['spec/**/*_spec.rb']
end
require 'yard'
@@ -24,4 +17,4 @@ YARD::Rake::YardocTask.new(:doc) do |t|
t.options = ['--no-private', '-m', 'markdown', '-o', './doc/public/yard']
end
-task :default => :test
+task :default => :spec
View
4 niceogiri.gemspec
@@ -21,9 +21,9 @@ Gem::Specification.new do |s|
s.add_dependency "nokogiri", [">= 1.4.0"]
- s.add_development_dependency "minitest", ["~> 1.7.1"]
+ s.add_development_dependency "rspec", [">= 2.7.0"]
s.add_development_dependency "bundler", ["~> 1.0.0"]
- s.add_development_dependency "rcov", ["~> 0.9.9"]
s.add_development_dependency "yard", ["~> 0.6.1"]
s.add_development_dependency "rake"
+ s.add_development_dependency "guard-rspec"
end
View
78 spec/niceogiri/core_ext/nokogiri_spec.rb
@@ -1,92 +1,92 @@
require 'spec_helper'
describe 'Nokogiri::XML::Node' do
- before { @doc = Nokogiri::XML::Document.new }
+ let(:doc) { Nokogiri::XML::Document.new }
it 'aliases #name to #element_name' do
- node = Nokogiri::XML::Node.new 'foo', @doc
- node.must_respond_to :element_name
- node.element_name.must_equal node.name
+ node = Nokogiri::XML::Node.new 'foo', doc
+ node.should respond_to :element_name
+ node.element_name.should == node.name
end
it 'aliases #name= to #element_name=' do
- node = Nokogiri::XML::Node.new 'foo', @doc
- node.must_respond_to :element_name=
- node.element_name.must_equal node.name
+ 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.must_equal 'bar'
+ node.element_name.should == 'bar'
end
it 'allows symbols as hash keys for attributes' do
- attrs = Nokogiri::XML::Node.new('foo', @doc)
+ attrs = Nokogiri::XML::Node.new('foo', doc)
attrs['foo'] = 'bar'
- attrs['foo'].must_equal 'bar'
- attrs[:foo].must_equal 'bar'
+ attrs['foo'].should == 'bar'
+ attrs[:foo].should == 'bar'
end
it 'ensures a string is passed to the attribute setter' do
- attrs = Nokogiri::XML::Node.new('foo', @doc)
+ attrs = Nokogiri::XML::Node.new('foo', doc)
attrs[:foo] = 1
- attrs[:foo].must_equal '1'
+ attrs[:foo].should == '1'
attrs[:some_attr] = :bah
- attrs[:some_attr].must_equal 'bah'
+ attrs[: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 = Nokogiri::XML::Node.new('foo', doc)
attrs[:foo] = 1
- attrs[:foo].must_equal '1'
+ attrs[:foo].should == '1'
attrs[:some_attr] = [:bah, :boo]
- attrs[:some_attr].must_equal 'bahboo'
+ attrs[:some_attr].should == 'bahboo'
end
it 'removes an attribute when set to nil' do
- attrs = Nokogiri::XML::Node.new('foo', @doc)
+ attrs = Nokogiri::XML::Node.new('foo', doc)
attrs['foo'] = 'bar'
- attrs['foo'].must_equal 'bar'
+ attrs['foo'].should == 'bar'
attrs['foo'] = nil
- attrs['foo'].must_be_nil
+ attrs['foo'].should be_nil
end
it 'allows attribute values to change' do
- attrs = Nokogiri::XML::Node.new('foo', @doc)
+ attrs = Nokogiri::XML::Node.new('foo', doc)
attrs['foo'] = 'bar'
- attrs['foo'].must_equal 'bar'
+ attrs['foo'].should == 'bar'
attrs['foo'] = 'baz'
- attrs['foo'].must_equal 'baz'
+ attrs['foo'].should == 'baz'
end
it 'allows symbols as the path in #xpath' do
- node = Nokogiri::XML::Node.new('foo', @doc)
- node.must_respond_to :find
- @doc.root = node
- @doc.xpath(:foo).first.wont_be_nil
- @doc.xpath(:foo).first.must_equal @doc.xpath('/foo').first
+ node = Nokogiri::XML::Node.new('foo', doc)
+ node.should respond_to :find
+ doc.root = node
+ 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 = Nokogiri::XML::Node.new('foo', doc)
node.namespace = node.add_namespace('bar', 'baz')
- @doc.root = node
- node.xpath('/bar:foo', :bar => 'baz').first.wont_be_nil
+ doc.root = node
+ node.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.must_respond_to :find
- @doc.root = node
- node.find('/foo').first.wont_be_nil
+ node = Nokogiri::XML::Node.new('foo', doc)
+ node.should respond_to :find
+ doc.root = node
+ node.find('/foo').first.should_not be_nil
end
it 'has a helper function #find_first' do
- node = Nokogiri::XML::Node.new('foo', @doc)
- node.must_respond_to :find
- @doc.root = node
- node.find_first('/foo').must_equal node.find('/foo').first
+ node = Nokogiri::XML::Node.new('foo', doc)
+ node.should respond_to :find
+ doc.root = node
+ node.find_first('/foo').should == node.find('/foo').first
end
end
View
106 spec/niceogiri/xml/node_spec.rb
@@ -3,89 +3,89 @@
module Niceogiri
module XML
describe Node do
- before { @doc = Nokogiri::XML::Document.new }
+ let(:doc) { Nokogiri::XML::Document.new }
it 'generates a new node automatically setting the document' do
n = Node.new 'foo'
- n.element_name.must_equal 'foo'
- n.document.wont_equal @doc
+ n.element_name.should == 'foo'
+ n.document.should_not == doc
end
it 'sets the new document root to the node' do
n = Node.new 'foo'
- n.document.root.must_equal n
+ n.document.root.should == n
end
it 'does not set the document root if the document is provided' do
- n = Node.new 'foo', @doc
- n.document.root.wont_equal n
+ n = Node.new 'foo', doc
+ n.document.root.should_not == n
end
it 'generates a new node with the given document' do
- n = Node.new 'foo', @doc
- n.element_name.must_equal 'foo'
- n.document.must_equal @doc
+ n = Node.new 'foo', doc
+ n.element_name.should == 'foo'
+ n.document.should == doc
end
it 'provides an attribute reader' do
foo = Node.new
- foo.read_attr(:bar).must_be_nil
+ foo.read_attr(:bar).should be_nil
foo[:bar] = 'baz'
- foo.read_attr(:bar).must_equal 'baz'
+ foo.read_attr(:bar).should == 'baz'
end
it 'provides an attribute reader with converstion' do
foo = Node.new
- foo.read_attr(:bar, :to_sym).must_be_nil
+ foo.read_attr(:bar, :to_sym).should be_nil
foo[:bar] = 'baz'
- foo.read_attr(:bar, :to_sym).must_equal :baz
+ foo.read_attr(:bar, :to_sym).should == :baz
end
it 'provides an attribute writer' do
foo = Node.new
- foo[:bar].must_be_nil
+ foo[:bar].should be_nil
foo.write_attr(:bar, 'baz')
- foo[:bar].must_equal 'baz'
+ foo[:bar].should == 'baz'
end
it 'provides a content reader' do
foo = Node.new('foo')
foo << (bar = Node.new('bar', foo.document))
bar.content = 'baz'
- foo.read_content(:bar).must_equal 'baz'
+ foo.read_content(:bar).should == 'baz'
end
it 'provides a content reader that converts the value' do
foo = Node.new('foo')
foo << (bar = Node.new('bar', foo.document))
bar.content = 'baz'
- foo.read_content(:bar, :to_sym).must_equal :baz
+ foo.read_content(:bar, :to_sym).should == :baz
end
it 'provides a content writer' do
foo = Node.new('foo')
foo.set_content_for :bar, 'baz'
- foo.content_from(:bar).must_equal 'baz'
+ foo.content_from(:bar).should == 'baz'
end
it 'provides a content writer that removes a child when set to nil' do
foo = Node.new('foo')
foo << (bar = Node.new('bar', foo.document))
bar.content = 'baz'
- foo.content_from(:bar).must_equal 'baz'
- foo.xpath('bar').wont_be_empty
+ foo.content_from(:bar).should == 'baz'
+ foo.xpath('bar').should_not be_empty
foo.set_content_for :bar, nil
- foo.content_from(:bar).must_be_nil
- foo.xpath('bar').must_be_empty
+ foo.content_from(:bar).should be_nil
+ foo.xpath('bar').should be_empty
end
it 'provides "attr_accessor" for namespace' do
n = Node.new('foo')
- n.namespace.must_be_nil
+ n.namespace.should be_nil
n.namespace = 'foo:bar'
- n.namespace_href.must_equal 'foo:bar'
+ n.namespace_href.should == 'foo:bar'
end
it 'will remove a child element' do
@@ -93,9 +93,9 @@ module XML
n << Node.new('bar', n.document)
n << Node.new('bar', n.document)
- n.find(:bar).size.must_equal 2
+ n.find(:bar).size.should == 2
n.remove_child 'bar'
- n.find(:bar).size.must_equal 1
+ n.find(:bar).size.should == 1
end
it 'will remove a child with a specific xmlns' do
@@ -105,11 +105,11 @@ module XML
c.namespace = 'foo:bar'
n << c
- n.find(:bar).size.must_equal 1
- n.find('//xmlns:bar', :xmlns => 'foo:bar').size.must_equal 1
+ n.find(:bar).size.should == 1
+ n.find('//xmlns:bar', :xmlns => 'foo:bar').size.should == 1
n.remove_child '//xmlns:bar', :xmlns => 'foo:bar'
- n.find(:bar).size.must_equal 1
- n.find('//xmlns:bar', :xmlns => 'foo:bar').size.must_equal 0
+ n.find(:bar).size.should == 1
+ n.find('//xmlns:bar', :xmlns => 'foo:bar').size.should == 0
end
it 'will remove all child elements' do
@@ -117,16 +117,16 @@ module XML
n << Node.new('bar')
n << Node.new('bar')
- n.find(:bar).size.must_equal 2
+ n.find(:bar).size.should == 2
n.remove_children 'bar'
- n.find(:bar).size.must_equal 0
+ n.find(:bar).size.should == 0
end
it 'provides a copy mechanism' do
n = Node.new 'foo'
n2 = n.copy
- n2.object_id.wont_equal n.object_id
- n2.element_name.must_equal n.element_name
+ n2.object_id.should_not == n.object_id
+ n2.element_name.should == n.element_name
end
it 'provides an inherit mechanism' do
@@ -136,15 +136,15 @@ module XML
n2['foo'] = 'bar'
n.inherit(n2)
- n['foo'].must_equal 'bar'
- n.content.must_equal 'bar'
- n2.to_s.must_equal n.to_s
+ n['foo'].should == 'bar'
+ n.content.should == 'bar'
+ n2.to_s.should == n.to_s
end
it 'holds on to namespaces when inheriting content' do
n = Nokogiri::XML.parse('<message><bar:foo xmlns:bar="http://bar.com"></message>').root
n2 = Node.new('message').inherit n
- n2.to_s.must_equal n.to_s
+ n2.to_s.should == n.to_s
end
it 'provides a mechanism to inherit attrs' do
@@ -153,51 +153,51 @@ module XML
n2['foo'] = 'bar'
n.inherit_attrs(n2.attributes)
- n['foo'].must_equal 'bar'
+ n['foo'].should == 'bar'
end
it 'has a content_from helper that pulls the content from a child node' do
f = Node.new('foo')
f << (b = Node.new('bar'))
b.content = 'content'
- f.content_from(:bar).must_equal 'content'
+ f.content_from(:bar).should == 'content'
end
it 'returns nil when sent #content_from and a missing node' do
f = Node.new('foo')
- f.content_from(:bar).must_be_nil
+ f.content_from(:bar).should be_nil
end
it 'creates a new node and sets content when sent #set_content_for' do
f = Node.new('foo')
- f.must_respond_to :set_content_for
- f.xpath('bar').must_be_empty
+ f.should respond_to :set_content_for
+ f.xpath('bar').should be_empty
f.set_content_for :bar, :baz
- f.xpath('bar').wont_be_empty
- f.xpath('bar').first.content.must_equal 'baz'
+ f.xpath('bar').should_not be_empty
+ f.xpath('bar').first.content.should == 'baz'
end
it 'removes a child node when sent #set_content_for with nil' do
f = Node.new('foo')
f << (b = Node.new('bar'))
- f.must_respond_to :set_content_for
- f.xpath('bar').wont_be_empty
+ f.should respond_to :set_content_for
+ f.xpath('bar').should_not be_empty
f.set_content_for :bar, nil
- f.xpath('bar').must_be_empty
+ f.xpath('bar').should be_empty
end
it 'will change the content of an existing node when sent #set_content_for' do
f = Node.new('foo')
f << (b = Node.new('bar'))
b.content = 'baz'
- f.must_respond_to :set_content_for
- f.xpath('bar').wont_be_empty
- f.xpath('bar').first.content.must_equal 'baz'
+ f.should respond_to :set_content_for
+ f.xpath('bar').should_not be_empty
+ f.xpath('bar').first.content.should == 'baz'
control = f.xpath('bar').first.pointer_id
f.set_content_for :bar, 'fiz'
- f.xpath('bar').first.content.must_equal 'fiz'
- f.xpath('bar').first.pointer_id.must_equal control
+ f.xpath('bar').first.content.should == 'fiz'
+ f.xpath('bar').first.pointer_id.should == control
end
end
end
View
13 spec/spec_helper.rb
@@ -1,6 +1,11 @@
-$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
+%w{
+ rspec
+ niceogiri
+}.each { |lib| require lib }
-require 'niceogiri'
-require 'minitest/spec'
+Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
-MiniTest::Unit.autorun
+RSpec.configure do |config|
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+end
Please sign in to comment.
Something went wrong with that request. Please try again.