From 58c6ee71672c8b66787b2117da3e30221de86e74 Mon Sep 17 00:00:00 2001 From: Bohuslav Kabrda Date: Wed, 1 Feb 2012 09:49:08 +0100 Subject: [PATCH] Enable tests. - Add patches for the failing tests. - Removed unnecessary ParseTree dependency. --- rubygem-thor.spec | 48 +++++--- thor-allow-random-test-execution-order.patch | 29 +++++ thor-fix-method-missing.patch | 120 +++++++++++++++++++ thor-fix-rake-desc-not-being-passed.patch | 20 ++++ thor-rake-0.9-compat.patch | 115 ++++++++++++++++++ 5 files changed, 315 insertions(+), 17 deletions(-) create mode 100644 thor-allow-random-test-execution-order.patch create mode 100644 thor-fix-method-missing.patch create mode 100644 thor-fix-rake-desc-not-being-passed.patch create mode 100644 thor-rake-0.9-compat.patch diff --git a/rubygem-thor.spec b/rubygem-thor.spec index bcf4215..607d2c9 100644 --- a/rubygem-thor.spec +++ b/rubygem-thor.spec @@ -6,23 +6,29 @@ Summary: Scripting framework that replaces rake, sake and rubigen Name: rubygem-%{gem_name} Version: 0.14.6 -Release: 4%{?dist} +Release: 5%{?dist} Group: Development/Languages License: MIT URL: http://github.com/wycats/thor Source0: http://rubygems.org/download/%{gem_name}-%{version}.gem +# all these patches should be contained in next version +Patch0: thor-allow-random-test-execution-order.patch +Patch1: thor-rake-0.9-compat.patch +Patch2: thor-fix-method-missing.patch +Patch3: thor-fix-rake-desc-not-being-passed.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: ruby(rubygems) Requires: ruby(abi) = %{rubyabi} Requires: rubygem(ruby2ruby) -Requires: rubygem(ParseTree) Requires: rubygem(rake) Requires: rubygem(diff-lcs) BuildRequires: rubygems-devel BuildRequires: ruby(abi) = %{rubyabi} -#BuildRequires(check): rubygem(rspec) -# No rdoc or fakeweb gem packages yet -#BuildRequires(check): rubygem(rake), rubygem(diff-lcs), rubygem(rdoc), rubygem(fakeweb) +BuildRequires: rubygem(rspec-core) +BuildRequires: rubygem(rake) +BuildRequires: rubygem(diff-lcs) +BuildRequires: rubygem(rdoc) +BuildRequires: rubygem(fakeweb) BuildArch: noarch Provides: rubygem(%{gem_name}) = %{version} @@ -41,7 +47,6 @@ This package contains documentation for %{name}. %prep %setup -q -c -T -%build mkdir -p .%{gem_dir} gem install -V \ --local \ @@ -49,6 +54,15 @@ gem install -V \ --force --rdoc \ %{SOURCE0} +pushd .%{gem_instdir} +%patch0 -p1 +%patch1 -p1 +%patch2 -p1 +%patch3 -p1 +popd + +%build + %install rm -rf %{buildroot} mkdir -p %{buildroot}%{gem_dir} @@ -65,17 +79,12 @@ find %{buildroot}%{gem_instdir}/bin -type f | \ %clean rm -rf %{buildroot} -# Commented out until we have rspec ~> 2.1 in Fedora. -# We'll also have to add a patch removing the simplecov -# dependency until ruby 1.9 is in Fedora -#%check -#pushd %{buildroot}%{gem_instdir} -#rspec spec - -# Can't yet run %%check missing a couple dependencies -#%check -#pushd .%{gem_instdir} -#ruby -Ilib bin/thor :spec +%check +pushd %{buildroot}%{gem_instdir} +# kill simplecov dependency +sed -i '3,7d' spec/spec_helper.rb +rspec spec +popd %files %defattr(-,root,root,-) @@ -97,6 +106,11 @@ rm -rf %{buildroot} %{gem_docdir} %changelog +* Wed Feb 01 2012 Bohuslav Kabrda - 0.14.6-5 +- Enable tests. +- Add patches for the failing tests. +- Removed unnecessary ParseTree dependency. + * Mon Jan 30 2012 Bohuslav Kabrda - 0.14.6-4 - Rebuilt for Ruby 1.9.3. diff --git a/thor-allow-random-test-execution-order.patch b/thor-allow-random-test-execution-order.patch new file mode 100644 index 0000000..a05f2a8 --- /dev/null +++ b/thor-allow-random-test-execution-order.patch @@ -0,0 +1,29 @@ +commit fb1a829d173a633446c56b4d0ed665312882e83b +Author: Brian Donovan +Date: Tue Sep 20 09:31:49 2011 -0700 + + Replace ARGV with an empty array before each spec run. + + Some of the specs were leaving ARGV in a non-pristine state (such as + those in runner_spec.rb), which was then implicitly used in + Thor::Base.start et al. It happened to be the case that the order in + which rspec was loading and running the specs made this not a problem, + but if the specs were run in a randomized order it could be a problem. + + Closes #171. + +diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb +index 00181ad..175637d 100644 +--- a/spec/spec_helper.rb ++++ b/spec/spec_helper.rb +@@ -29,6 +29,10 @@ load File.join(File.dirname(__FILE__), "fixtures", "script.thor") + load File.join(File.dirname(__FILE__), "fixtures", "invoke.thor") + + RSpec.configure do |config| ++ config.before :each do ++ ARGV.replace [] ++ end ++ + def capture(stream) + begin + stream = stream.to_s diff --git a/thor-fix-method-missing.patch b/thor-fix-method-missing.patch new file mode 100644 index 0000000..4282f27 --- /dev/null +++ b/thor-fix-method-missing.patch @@ -0,0 +1,120 @@ +commit 018b25811118c3bb95162324b3feae3a1e2b9923 +Author: Yehuda Katz +Date: Sat Jul 2 20:51:23 2011 -0700 + + Get method_missing working again. I'm not sure how it was working before, but the tests didn't pass. + +# Altered a bit to work with this version. +diff --git a/lib/thor/task.rb b/lib/thor/task.rb +index 8dcff53..f94d5b6 100644 +--- a/lib/thor/task.rb ++++ b/lib/thor/task.rb +@@ -18,8 +18,15 @@ class Thor + # By default, a task invokes a method in the thor class. You can change this + # implementation to create custom tasks. + def run(instance, args=[]) +- public_method?(instance) ? +- instance.send(name, *args) : instance.class.handle_no_task_error(name) ++ if private_method?(instance) ++ instance.class.handle_no_task_error(name) ++ elsif public_method?(instance) ++ instance.send(name, *args) ++ elsif local_method?(instance, :method_missing) ++ instance.send(:method_missing, name.to_sym, *args) ++ else ++ instance.class.handle_no_task_error(name) ++ end + rescue ArgumentError => e + handle_argument_error?(instance, e, caller) ? + instance.class.handle_argument_error(self, e) : (raise e) +@@ -71,6 +78,15 @@ class Thor + (collection & [name.to_s, name.to_sym]).empty? + end + ++ def private_method?(instance) ++ !(instance.private_methods & [name.to_s, name.to_sym]).empty? ++ end ++ ++ def local_method?(instance, name) ++ methods = instance.public_methods(false) + instance.private_methods(false) + instance.protected_methods(false) ++ !(methods & [name.to_s, name.to_sym]).empty? ++ end ++ + def sans_backtrace(backtrace, caller) #:nodoc: + saned = backtrace.reject { |frame| frame =~ FILE_REGEXP } + saned -= caller +@@ -105,11 +121,7 @@ class Thor + + def run(instance, args=[]) + if (instance.methods & [name.to_s, name.to_sym]).empty? +- if ((instance.protected_methods + instance.public_methods) & ([:method_missing, "method_missing"])).empty? +- super +- else +- instance.send(:method_missing, name.to_sym, *args) +- end ++ super + else + instance.class.handle_no_task_error(name) + end +diff --git a/spec/task_spec.rb b/spec/task_spec.rb +index 1c7ea7c..3372de1 100644 +--- a/spec/task_spec.rb ++++ b/spec/task_spec.rb +@@ -11,21 +11,18 @@ describe Thor::Task do + + describe "#formatted_usage" do + it "includes namespace within usage" do +- Object.stub!(:namespace).and_return("foo") +- Object.stub!(:arguments).and_return([]) +- task(:bar => :required).formatted_usage(Object).should == "foo:can_has --bar=BAR" ++ object = Struct.new(:namespace, :arguments).new("foo", []) ++ task(:bar => :required).formatted_usage(object).should == "foo:can_has --bar=BAR" + end + + it "removes default from namespace" do +- Object.stub!(:namespace).and_return("default:foo") +- Object.stub!(:arguments).and_return([]) +- task(:bar => :required).formatted_usage(Object).should == ":foo:can_has --bar=BAR" ++ object = Struct.new(:namespace, :arguments).new("default:foo", []) ++ task(:bar => :required).formatted_usage(object).should == ":foo:can_has --bar=BAR" + end + + it "injects arguments into usage" do +- Object.stub!(:namespace).and_return("foo") +- Object.stub!(:arguments).and_return([ Thor::Argument.new(:bar, nil, true, :string) ]) +- task(:foo => :required).formatted_usage(Object).should == "foo:can_has BAR --foo=FOO" ++ object = Struct.new(:namespace, :arguments).new("foo", [Thor::Argument.new(:bar, nil, true, :string)]) ++ task(:foo => :required).formatted_usage(object).should == "foo:can_has BAR --foo=FOO" + end + end + +@@ -55,15 +52,23 @@ describe Thor::Task do + describe "#run" do + it "runs a task by calling a method in the given instance" do + mock = mock() +- mock.should_receive(:send).with("can_has", 1, 2, 3) +- task.run(mock, [1, 2, 3]) ++ mock.should_receive(:can_has).and_return {|*args| args } ++ task.run(mock, [1, 2, 3]).should == [1, 2, 3] + end + + it "raises an error if the method to be invoked is private" do +- mock = mock() +- mock.should_receive(:private_methods).and_return(['can_has']) +- mock.class.should_receive(:handle_no_task_error).with("can_has") +- task.run(mock) ++ klass = Class.new do ++ def self.handle_no_task_error(name) ++ name ++ end ++ ++ private ++ def can_has ++ "fail" ++ end ++ end ++ ++ task.run(klass.new).should == "can_has" + end + end + end diff --git a/thor-fix-rake-desc-not-being-passed.patch b/thor-fix-rake-desc-not-being-passed.patch new file mode 100644 index 0000000..b639240 --- /dev/null +++ b/thor-fix-rake-desc-not-being-passed.patch @@ -0,0 +1,20 @@ +commit 36603c1811451d370da4915e24eed665fe805ae4 +Author: Gabriel Horner +Date: Mon Jul 4 14:44:07 2011 -0400 + + Fix rake desc not being passed to thor + +diff --git a/lib/thor/rake_compat.rb b/lib/thor/rake_compat.rb +index b3a8beb..c86e840 100644 +--- a/lib/thor/rake_compat.rb ++++ b/lib/thor/rake_compat.rb +@@ -46,7 +46,8 @@ self.instance_eval do + description << task.arg_names.map{ |n| n.to_s.upcase }.join(' ') + description.strip! + +- klass.desc description, task.comment || non_namespaced_name ++ klass.desc description, Rake.application.last_description || non_namespaced_name ++ Rake.application.last_description = nil + klass.send :define_method, non_namespaced_name do |*args| + Rake::Task[task.name.to_sym].invoke(*args) + end diff --git a/thor-rake-0.9-compat.patch b/thor-rake-0.9-compat.patch new file mode 100644 index 0000000..f2e3408 --- /dev/null +++ b/thor-rake-0.9-compat.patch @@ -0,0 +1,115 @@ +commit 11c8748933cc611972f32831657ab99e6701bd93 +Author: Yehuda Katz +Date: Sat Jul 2 20:50:39 2011 -0700 + + Upgrade Rake compatibility for the more constrained Rake 0.9 + +diff --git a/lib/thor/rake_compat.rb b/lib/thor/rake_compat.rb +index 0d0757f..b3a8beb 100644 +--- a/lib/thor/rake_compat.rb ++++ b/lib/thor/rake_compat.rb +@@ -1,4 +1,5 @@ + require 'rake' ++require 'rake/dsl_definition' + + class Thor + # Adds a compatibility layer to your Thor classes which allows you to use +@@ -16,6 +17,8 @@ class Thor + # end + # + module RakeCompat ++ include Rake::DSL if defined?(Rake::DSL) ++ + def self.rake_classes + @rake_classes ||= [] + end +@@ -29,12 +32,12 @@ class Thor + end + end + +-class Object #:nodoc: +- alias :rake_task :task +- alias :rake_namespace :namespace ++# override task on (main), for compatibility with Rake 0.9 ++self.instance_eval do ++ alias rake_namespace namespace + +- def task(*args, &block) +- task = rake_task(*args, &block) ++ def task(*) ++ task = super + + if klass = Thor::RakeCompat.rake_classes.last + non_namespaced_name = task.name.split(':').last +@@ -52,7 +55,7 @@ class Object #:nodoc: + task + end + +- def namespace(name, &block) ++ def namespace(name) + if klass = Thor::RakeCompat.rake_classes.last + const_name = Thor::Util.camel_case(name.to_s).to_sym + klass.const_set(const_name, Class.new(Thor)) +@@ -60,7 +63,8 @@ class Object #:nodoc: + Thor::RakeCompat.rake_classes << new_klass + end + +- rake_namespace(name, &block) ++ super + Thor::RakeCompat.rake_classes.pop + end + end ++ +diff --git a/lib/thor/task.rb b/lib/thor/task.rb +index 6db3b60..8dcff53 100644 +--- a/lib/thor/task.rb ++++ b/lib/thor/task.rb +@@ -104,7 +104,11 @@ class Thor + + def run(instance, args=[]) + if (instance.methods & [name.to_s, name.to_sym]).empty? +- super ++ if ((instance.protected_methods + instance.public_methods) & ([:method_missing, "method_missing"])).empty? ++ super ++ else ++ instance.send(:method_missing, name.to_sym, *args) ++ end + else + instance.class.handle_no_task_error(name) + end +diff --git a/spec/rake_compat_spec.rb b/spec/rake_compat_spec.rb +index f8d694c..0b642aa 100644 +--- a/spec/rake_compat_spec.rb ++++ b/spec/rake_compat_spec.rb +@@ -2,20 +2,24 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') + require 'thor/rake_compat' + require 'rake/tasklib' + ++$main = self ++ + class RakeTask < Rake::TaskLib + def initialize + define + end + + def define +- desc "Say it's cool" +- task :cool do +- puts "COOL" +- end ++ $main.instance_eval do ++ desc "Say it's cool" ++ task :cool do ++ puts "COOL" ++ end + +- namespace :hiper_mega do +- task :super do +- puts "HIPER MEGA SUPER" ++ namespace :hiper_mega do ++ task :super do ++ puts "HIPER MEGA SUPER" ++ end + end + end + end