mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Initial sweep of cleaning up specs (Ruby < v1.9.3, Rails < v3)
This commit is contained in:
parent
3cc61d68d9
commit
d8e3b3c051
3 changed files with 13 additions and 125 deletions
|
@ -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
|
||||
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
|
||||
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
|
||||
#<User:0x01234567
|
||||
@attributes_cache = {},
|
||||
|
@ -179,27 +170,6 @@ EOS
|
|||
"rank" => nil
|
||||
}
|
||||
>
|
||||
EOS
|
||||
# ActiveRecord 2.x
|
||||
#--------------------------------------------------------------------------
|
||||
elsif ActiveRecord::VERSION::STRING.start_with?('2.')
|
||||
str = <<-EOS.strip
|
||||
#<User:0x01234567
|
||||
@attributes_cache = {},
|
||||
@changed_attributes = {
|
||||
"admin" => 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] #<User:0x01234567
|
||||
|
@ -312,45 +282,6 @@ EOS
|
|||
}
|
||||
>
|
||||
]
|
||||
EOS
|
||||
# ActiveRecord 2.0.x
|
||||
#--------------------------------------------------------------------------
|
||||
elsif ActiveRecord::VERSION::STRING.start_with?('2.')
|
||||
str = <<-EOS.strip
|
||||
[
|
||||
[0] #<User:0x01234567
|
||||
@attributes_cache = {},
|
||||
@changed_attributes = {
|
||||
"admin" => 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] #<User:0x01234567
|
||||
@attributes_cache = {},
|
||||
@changed_attributes = {
|
||||
"admin" => 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
|
||||
else
|
||||
out.should =~ /\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/
|
||||
end
|
||||
|
@ -417,15 +344,11 @@ 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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue LoadError => error
|
||||
puts "Skipping ActiveRecord specs: #{error}"
|
||||
end
|
||||
|
|
|
@ -33,13 +33,11 @@ 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
|
||||
end
|
||||
|
||||
it "returns value passed as a parameter" do
|
||||
object = rand
|
||||
|
@ -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|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|
|
||||
else
|
||||
out.should == %Q|<pre>[red]"hello"[/red]</pre>|
|
||||
end
|
||||
end
|
||||
|
||||
it "shoud not raise ArgumentError when formatting HTML (shade color)" do
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue