From d8e3b3c05126d0a27112066b3414797bd5eec76c Mon Sep 17 00:00:00 2001 From: Michael Dvorkin Date: Sat, 5 Oct 2013 11:32:54 -0700 Subject: [PATCH] Initial sweep of cleaning up specs (Ruby < v1.9.3, Rails < v3) --- spec/ext/active_record_spec.rb | 93 +++------------------------------- spec/misc_spec.rb | 16 ++---- spec/spec_helper.rb | 29 ----------- 3 files changed, 13 insertions(+), 125 deletions(-) diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index 20f00df..e5d0d11 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -4,7 +4,7 @@ begin require 'active_record' require 'awesome_print/ext/active_record' - if defined?(ActiveRecord::VERSION::MAJOR) && ActiveRecord::VERSION::MAJOR >= 2 + if defined?(ActiveRecord::VERSION::MAJOR) && ActiveRecord::VERSION::MAJOR >= 3 # Create tableless ActiveRecord model. #------------------------------------------------------------------------------ @@ -74,11 +74,7 @@ begin :rank => 1 } EOS - if RUBY_VERSION < '1.9' - str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992') - else - str.sub!('?', '1992-10-10 12:30:00 UTC') - end + str.sub!('?', '1992-10-10 12:30:00 UTC') out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str end @@ -102,13 +98,8 @@ EOS } ] EOS - if RUBY_VERSION < '1.9' - str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992') - str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003') - else - str.sub!('??', '1992-10-10 12:30:00 UTC') - str.sub!('?!', '2003-05-26 14:15:00 UTC') - end + str.sub!('??', '1992-10-10 12:30:00 UTC') + str.sub!('?!', '2003-05-26 14:15:00 UTC') out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str end end @@ -157,7 +148,7 @@ EOS EOS # ActiveRecord 3.0.x #-------------------------------------------------------------------------- - elsif ActiveRecord::VERSION::STRING.start_with?('3.0') + elsif ActiveRecord::VERSION::STRING >= "3.0" str = <<-EOS.strip # nil } > -EOS - # ActiveRecord 2.x - #-------------------------------------------------------------------------- - elsif ActiveRecord::VERSION::STRING.start_with?('2.') - str = <<-EOS.strip -# nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - }, - @new_record = true, - attr_accessor :attributes = { - "admin" => false, - "created_at" => "1992-10-10 12:30:00", - "name" => "Diana", - "rank" => 1 - } -> EOS end str.sub!('?', '1992-10-10 12:30:00') @@ -268,7 +238,7 @@ EOS EOS # ActiveRecord 3.0.x #-------------------------------------------------------------------------- - elsif ActiveRecord::VERSION::STRING.start_with?('3.0') + elsif ActiveRecord::VERSION::STRING >= "3.0" str = <<-EOS.strip [ [0] # ] -EOS - # ActiveRecord 2.0.x - #-------------------------------------------------------------------------- - elsif ActiveRecord::VERSION::STRING.start_with?('2.') - str = <<-EOS.strip -[ - [0] # nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - }, - @new_record = true, - attr_accessor :attributes = { - "admin" => false, - "created_at" => "1992-10-10 12:30:00", - "name" => "Diana", - "rank" => 1 - } - >, - [1] # nil, - "created_at" => nil, - "name" => nil, - "rank" => nil - }, - @new_record = true, - attr_accessor :attributes = { - "admin" => true, - "created_at" => "2003-05-26 14:15:00", - "name" => "Laura", - "rank" => 2 - } - > -] EOS end str.sub!('?', '1992-10-10 12:30:00') @@ -404,11 +335,7 @@ EOS out = @ap.send(:awesome, User.methods.grep(/first/)) if ActiveRecord::VERSION::STRING >= "3.2" - if RUBY_VERSION >= "1.9" - out.should =~ /\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/ - else - out.should =~ /\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/ - end + out.should =~ /\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/ else out.should =~ /\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/ end @@ -417,11 +344,7 @@ EOS out.should =~ /\sprimary_key\(.*?\)\s+User/ out = @ap.send(:awesome, User.methods.grep(/validate/)) - if ActiveRecord::VERSION::MAJOR < 3 - out.should =~ /\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/ - else - out.should =~ /\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/ - end + out.should =~ /\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/ end end end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 54a61fc..8061dcf 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -33,12 +33,10 @@ describe "AwesomePrint" do end # See https://github.com/michaeldv/awesome_print/issues/85 - if RUBY_VERSION >= "1.8.7" - it "handle array grep when a method is defined in C and thus doesn't have a binding" do - arr = (0..6).to_a - grepped = arr.grep(1..4, &:succ) - grepped.ai(:plain => true, :multiline => false).should == '[ 2, 3, 4, 5 ]' - end + it "handle array grep when a method is defined in C and thus doesn't have a binding" do + arr = (0..6).to_a + grepped = arr.grep(1..4, &:succ) + grepped.ai(:plain => true, :multiline => false).should == '[ 2, 3, 4, 5 ]' end it "returns value passed as a parameter" do @@ -177,11 +175,7 @@ EOS it "shoud not raise ArgumentError when formatting HTML" do out = "hello".ai(:color => { :string => :red }, :html => true) - if RUBY_VERSION >= "1.9" - out.should == %Q|
[red]"hello"[/red]
| - else - out.should == %Q|
[red]"hello"[/red]
| - end + out.should == %Q|
[red]"hello"[/red]
| end it "shoud not raise ArgumentError when formatting HTML (shade color)" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9a4ebab..be8c569 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,32 +33,3 @@ end # The following is needed for the Infinity Test. It runs tests as subprocesses, # which sets STDOUT.tty? to false and would otherwise prematurely disallow colors. ### AwesomePrint.force_colors! - -# Ruby 1.8.6 only: define missing String methods that are needed for the specs to pass. -if RUBY_VERSION < '1.8.7' - class String - def shellescape # Taken from Ruby 1.9.2 standard library, see lib/shellwords.rb. - return "''" if self.empty? - str = self.dup - str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1") - str.gsub!(/\n/, "'\n'") - str - end - - def start_with?(*prefixes) - prefixes.each do |prefix| - prefix = prefix.to_s - return true if prefix == self[0, prefix.size] - end - false - end - - def end_with?(*suffixes) - suffixes.each do |suffix| - suffix = suffix.to_s - return true if suffix == self[-suffix.size, suffix.size] - end - false - end - end -end