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 'active_record'
|
||||||
require 'awesome_print/ext/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.
|
# Create tableless ActiveRecord model.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
@ -74,11 +74,7 @@ begin
|
||||||
:rank => 1
|
:rank => 1
|
||||||
}
|
}
|
||||||
EOS
|
EOS
|
||||||
if RUBY_VERSION < '1.9'
|
str.sub!('?', '1992-10-10 12:30:00 UTC')
|
||||||
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
|
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,13 +98,8 @@ EOS
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
EOS
|
EOS
|
||||||
if RUBY_VERSION < '1.9'
|
str.sub!('??', '1992-10-10 12:30:00 UTC')
|
||||||
str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992')
|
str.sub!('?!', '2003-05-26 14:15:00 UTC')
|
||||||
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
|
out.gsub(/0x([a-f\d]+)/, "0x01234567").should == str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -157,7 +148,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
# ActiveRecord 3.0.x
|
# ActiveRecord 3.0.x
|
||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
elsif ActiveRecord::VERSION::STRING.start_with?('3.0')
|
elsif ActiveRecord::VERSION::STRING >= "3.0"
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
#<User:0x01234567
|
#<User:0x01234567
|
||||||
@attributes_cache = {},
|
@attributes_cache = {},
|
||||||
|
@ -179,27 +170,6 @@ EOS
|
||||||
"rank" => nil
|
"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
|
EOS
|
||||||
end
|
end
|
||||||
str.sub!('?', '1992-10-10 12:30:00')
|
str.sub!('?', '1992-10-10 12:30:00')
|
||||||
|
@ -268,7 +238,7 @@ EOS
|
||||||
EOS
|
EOS
|
||||||
# ActiveRecord 3.0.x
|
# ActiveRecord 3.0.x
|
||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
elsif ActiveRecord::VERSION::STRING.start_with?('3.0')
|
elsif ActiveRecord::VERSION::STRING >= "3.0"
|
||||||
str = <<-EOS.strip
|
str = <<-EOS.strip
|
||||||
[
|
[
|
||||||
[0] #<User:0x01234567
|
[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
|
EOS
|
||||||
end
|
end
|
||||||
str.sub!('?', '1992-10-10 12:30:00')
|
str.sub!('?', '1992-10-10 12:30:00')
|
||||||
|
@ -404,11 +335,7 @@ EOS
|
||||||
out = @ap.send(:awesome, User.methods.grep(/first/))
|
out = @ap.send(:awesome, User.methods.grep(/first/))
|
||||||
|
|
||||||
if ActiveRecord::VERSION::STRING >= "3.2"
|
if ActiveRecord::VERSION::STRING >= "3.2"
|
||||||
if RUBY_VERSION >= "1.9"
|
out.should =~ /\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/
|
||||||
out.should =~ /\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/
|
|
||||||
else
|
|
||||||
out.should =~ /\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
out.should =~ /\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/
|
out.should =~ /\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/
|
||||||
end
|
end
|
||||||
|
@ -417,11 +344,7 @@ EOS
|
||||||
out.should =~ /\sprimary_key\(.*?\)\s+User/
|
out.should =~ /\sprimary_key\(.*?\)\s+User/
|
||||||
|
|
||||||
out = @ap.send(:awesome, User.methods.grep(/validate/))
|
out = @ap.send(:awesome, User.methods.grep(/validate/))
|
||||||
if ActiveRecord::VERSION::MAJOR < 3
|
out.should =~ /\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/
|
||||||
out.should =~ /\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/
|
|
||||||
else
|
|
||||||
out.should =~ /\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,12 +33,10 @@ describe "AwesomePrint" do
|
||||||
end
|
end
|
||||||
|
|
||||||
# See https://github.com/michaeldv/awesome_print/issues/85
|
# 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
|
||||||
it "handle array grep when a method is defined in C and thus doesn't have a binding" do
|
arr = (0..6).to_a
|
||||||
arr = (0..6).to_a
|
grepped = arr.grep(1..4, &:succ)
|
||||||
grepped = arr.grep(1..4, &:succ)
|
grepped.ai(:plain => true, :multiline => false).should == '[ 2, 3, 4, 5 ]'
|
||||||
grepped.ai(:plain => true, :multiline => false).should == '[ 2, 3, 4, 5 ]'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns value passed as a parameter" do
|
it "returns value passed as a parameter" do
|
||||||
|
@ -177,11 +175,7 @@ EOS
|
||||||
|
|
||||||
it "shoud not raise ArgumentError when formatting HTML" do
|
it "shoud not raise ArgumentError when formatting HTML" do
|
||||||
out = "hello".ai(:color => { :string => :red }, :html => true)
|
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>|
|
||||||
out.should == %Q|<pre>[red]<kbd style="color:red">"hello"</kbd>[/red]</pre>|
|
|
||||||
else
|
|
||||||
out.should == %Q|<pre>[red]"hello"[/red]</pre>|
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "shoud not raise ArgumentError when formatting HTML (shade color)" do
|
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,
|
# 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.
|
# which sets STDOUT.tty? to false and would otherwise prematurely disallow colors.
|
||||||
### AwesomePrint.force_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…
Add table
Add a link
Reference in a new issue