Permalink
Browse files

Port specs to rspec.

  • Loading branch information...
1 parent 4d52498 commit a557ce36e200f267cfa45f34e2f3e7df51008e76 @libc committed Feb 12, 2012
View
@@ -1,2 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
pkg/*
-doc/*
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
@@ -0,0 +1,6 @@
+source :rubygems
+gemspec
+
+gem 'rspec', '~> 2.0'
+gem 'rake'
+gem 'rr'
View
@@ -1,24 +1,6 @@
-require 'rubygems'
-begin
- require 'echoe'
- Echoe.new('tidy_ffi') do |p|
- p.author = 'Eugene Pimenov'
- p.summary = 'Tidy library interface via FFI'
- p.url = 'http://github.com/libc/tidy_ffi'
- p.runtime_dependencies = ['ffi >=0.3.5']
- # p.development_dependencies = ['rr', 'matchy', 'context']
- p.project = 'tidy-ffi'
- p.email = 'libc@libc.st'
- p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README\.rdoc|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
- p.retain_gemspec = true
- end
+require 'bundler/gem_tasks'
+require 'rspec/core/rake_task'
- # My common error
- task :rdoc => :doc do; end
-rescue LoadError => boom
- puts "You are missing a dependency required for meta-operations on this gem."
- puts "#{boom.to_s.capitalize}."
+RSpec::Core::RakeTask.new(:spec)
- desc 'No effect.'
- task :default do; end
-end
+task :default => :spec
View
@@ -0,0 +1,3 @@
+module TidyFFI
+ VERSION = "0.1.2"
+end
View
@@ -0,0 +1,84 @@
+require 'spec_helper'
+
+describe TidyFFI::Interface do
+ I = TidyFFI::Interface
+
+ describe "default_options" do
+ it "returns a hash" do
+ I.default_options.is_a?(Hash)
+ end
+
+ it "has show force_output option" do
+ I.default_options[:force_output][:name].should == :force_output
+ I.default_options[:force_output][:type].should == :boolean
+ end
+ end
+
+ describe "option_valid" do
+ it "returns false when unknown options is specified" do
+ I.option_valid?(:gobbledygook, '1').should == false
+ end
+
+ it "accepts yes, no, 1, 0, true, false as boolean values" do
+ stub(I).default_options { {:gobbledygook => {:type => :boolean}} }
+
+ %w{yes no 1 0 true false on off YeS}.each do |val|
+ I.option_valid?(:gobbledygook, val).should == true
+ end
+ I.option_valid?(:gobbledygook, 1).should == true
+ I.option_valid?(:gobbledygook, 0).should == true
+ I.option_valid?(:gobbledygook, true).should == true
+ I.option_valid?(:gobbledygook, false).should == true
+
+ I.option_valid?(:gobbledygook, "gobbledygook").should == false
+ end
+
+ it "accepts a number as a valid integer value" do
+ stub(I).default_options { {:gobbledygook => {:type => :integer}} }
+
+ I.option_valid?(:gobbledygook, 1).should == true
+ I.option_valid?(:gobbledygook, 0).should == true
+ I.option_valid?(:gobbledygook, "0").should == true
+ I.option_valid?(:gobbledygook, "1").should == true
+ I.option_valid?(:gobbledygook, "42").should == true
+
+ I.option_valid?(:gobbledygook, "gobbledygook").should == false
+ I.option_valid?(:gobbledygook, "true").should == false
+ end
+
+ it "accepts any string as a valid string value" do
+ stub(I).default_options { {:gobbledygook => {:type => :string}} }
+
+ I.option_valid?(:gobbledygook, 1).should == false
+ I.option_valid?(:gobbledygook, 0).should == false
+
+ I.option_valid?(:gobbledygook, "0").should == true
+ I.option_valid?(:gobbledygook, "1").should == true
+ I.option_valid?(:gobbledygook, "42").should == true
+ I.option_valid?(:gobbledygook, "gobbledygook").should == true
+ I.option_valid?(:gobbledygook, "true").should == true
+ end
+
+ it "accepts a symbols as a valid string value" do
+ stub(I).default_options { {:gobbledygook => {:type => :string}} }
+
+ I.option_valid?(:gobbledygook, :test).should == true
+ end
+
+ it "accepts number in range as a valid enum value" do
+ stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
+
+ I.option_valid?(:gobbledygook, 1).should == true
+ I.option_valid?(:gobbledygook, 0).should == true
+ I.option_valid?(:gobbledygook, 3).should == false
+ end
+
+ it "accepts string representation of enum value" do
+ stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
+
+ I.option_valid?(:gobbledygook, "one").should == true
+ I.option_valid?(:gobbledygook, "two").should == true
+ I.option_valid?(:gobbledygook, "three").should == false
+ end
+ end
+end
@@ -1,16 +1,16 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
+require 'spec_helper'
-class TestOptions < Test::Unit::TestCase
+describe TidyFFI::Tidy, 'options' do
T = TidyFFI::Tidy
- context "public interface" do
+ describe "public interface" do
[:default_options, :default_options=, :with_options, :validate_options].each do |method|
it "responds to #{method}" do
T.respond_to?(method)
end
end
end
- context "default_options method" do
+ describe "#default_options" do
before :each do
T.default_options.clear!
T.validate_options = false
@@ -47,7 +47,7 @@ class TestOptions < Test::Unit::TestCase
end
end
- context "options method" do
+ describe "#options" do
before :each do
T.validate_options = false
T.default_options.clear!
@@ -71,7 +71,7 @@ class TestOptions < Test::Unit::TestCase
end
end
- context "clear! method" do
+ describe "#clear!" do
it "clears options' options" do
@t.options.test = 1
@t.options.clear!
@@ -107,7 +107,7 @@ class TestOptions < Test::Unit::TestCase
end
end
- context "with_options proxy class" do
+ describe "with_options proxy class" do
before :each do
T.validate_options = false
end
@@ -130,4 +130,4 @@ class TestOptions < Test::Unit::TestCase
T.with_options(:test => 1).new('test').options.test.should == 1
end
end
-end
+end
View
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe TidyFFI::Tidy do
+ T = TidyFFI::Tidy
+ context "public interface" do
+ [[:initialize, -2],
+ [:clean, 0],
+ [:errors, 0]].each do |method, arity|
+ it "method #{method} has arity #{arity}" do
+ T.instance_method(method).arity.should == arity
+ end
+ end
+ end
+
+ context "simple cleanup" do
+ it "clean up text" do
+ T.new("test").clean.should =~ %r{<body>\s+test\s+</body>}
+ T.new("test").clean.should =~ %r{<meta name="generator" content=.+?Tidy.+?>}m
+
+ T.clean("test").should =~ %r{<body>\s+test\s+</body>}
+ T.clean("test").should =~ %r{<meta name="generator" content=.+?Tidy.+?>}m
+ end
+
+ it "doesn't die if called twice (bug #27200)" do
+ 2.times { T.with_options(:show_warnings => false).new("test").clean }
+ end
+ end
+
+ context "should have method for errors" do
+ it "have method for errors" do
+ t = T.new("test")
+ t.clean
+ t.errors.should =~ /Warning/
+ end
+ end
+
+
+ context "options validation" do
+ it "raises error on invalid option name" do
+ TidyFFI::Tidy.validate_options = true
+ lambda do
+ TidyFFI::Tidy.default_options = {:complete_garbage => true}
+ end.should raise_error(TidyFFI::Tidy::InvalidOptionName)
+ end
+
+ it "raises error on invalid option value" do
+ TidyFFI::Tidy.validate_options = true
+ lambda do
+ TidyFFI::Tidy.default_options = {:force_output => "utter trash"}
+ end.should raise_error(TidyFFI::Tidy::InvalidOptionValue)
+ end
+ end
+end
View
@@ -0,0 +1,6 @@
+require 'tidy_ffi'
+require 'rspec'
+
+RSpec.configure do |config|
+ config.mock_with :rr
+end
View
@@ -1,13 +0,0 @@
-require 'test/unit'
-
-require 'rubygems'
-require 'tidy_ffi'
-
-require 'rr'
-require 'matchy'
-require 'context'
-
-class Test::Unit::TestCase
- alias method_name name unless instance_methods.include?('method_name')
- include RR::Adapters::TestUnit unless instance_methods.include?('stub') || instance_methods.include?(:stub)
-end
View
@@ -1,86 +0,0 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
-
-class TestSimple < Test::Unit::TestCase
- I = TidyFFI::Interface
- context "TidyFFI::Interface" do
- context "default_options" do
- it "returns a hash" do
- I.default_options.is_a?(Hash)
- end
-
- it "has show force_output option" do
- I.default_options[:force_output][:name].should == :force_output
- I.default_options[:force_output][:type].should == :boolean
- end
- end
-
- context "option_valid" do
- it "returns false when unknown options is specified" do
- I.option_valid?(:gobbledygook, '1').should == false
- end
-
- it "accepts yes, no, 1, 0, true, false as boolean values" do
- stub(I).default_options { {:gobbledygook => {:type => :boolean}} }
-
- %w{yes no 1 0 true false on off YeS}.each do |val|
- I.option_valid?(:gobbledygook, val).should == true
- end
- I.option_valid?(:gobbledygook, 1).should == true
- I.option_valid?(:gobbledygook, 0).should == true
- I.option_valid?(:gobbledygook, true).should == true
- I.option_valid?(:gobbledygook, false).should == true
-
- I.option_valid?(:gobbledygook, "gobbledygook").should == false
- end
-
- it "accepts a number as a valid integer value" do
- stub(I).default_options { {:gobbledygook => {:type => :integer}} }
-
- I.option_valid?(:gobbledygook, 1).should == true
- I.option_valid?(:gobbledygook, 0).should == true
- I.option_valid?(:gobbledygook, "0").should == true
- I.option_valid?(:gobbledygook, "1").should == true
- I.option_valid?(:gobbledygook, "42").should == true
-
- I.option_valid?(:gobbledygook, "gobbledygook").should == false
- I.option_valid?(:gobbledygook, "true").should == false
- end
-
- it "accepts any string as a valid string value" do
- stub(I).default_options { {:gobbledygook => {:type => :string}} }
-
- I.option_valid?(:gobbledygook, 1).should == false
- I.option_valid?(:gobbledygook, 0).should == false
-
- I.option_valid?(:gobbledygook, "0").should == true
- I.option_valid?(:gobbledygook, "1").should == true
- I.option_valid?(:gobbledygook, "42").should == true
- I.option_valid?(:gobbledygook, "gobbledygook").should == true
- I.option_valid?(:gobbledygook, "true").should == true
-
- end
-
- it "accepts a symbols as a valid string value" do
- stub(I).default_options { {:gobbledygook => {:type => :string}} }
-
- I.option_valid?(:gobbledygook, :test).should == true
- end
-
- it "accepts number in range as a valid enum value" do
- stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
-
- I.option_valid?(:gobbledygook, 1).should == true
- I.option_valid?(:gobbledygook, 0).should == true
- I.option_valid?(:gobbledygook, 3).should == false
- end
-
- it "accepts string representation of enum value" do
- stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
-
- I.option_valid?(:gobbledygook, "one").should == true
- I.option_valid?(:gobbledygook, "two").should == true
- I.option_valid?(:gobbledygook, "three").should == false
- end
- end
- end
-end
Oops, something went wrong.

0 comments on commit a557ce3

Please sign in to comment.