mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Moved misc specs to spec/misc_specs.rb
This commit is contained in:
parent
8a222fb709
commit
fa958455ca
3 changed files with 90 additions and 85 deletions
|
@ -501,7 +501,6 @@ EOS
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Struct" do
|
||||
before do
|
||||
|
@ -573,89 +572,6 @@ EOS
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Misc" do
|
||||
it "handle weird objects that return nil on inspect" do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
nil
|
||||
end
|
||||
end
|
||||
weird.new.ai(:plain => true).should == ''
|
||||
end
|
||||
|
||||
it "handle frozen object.inspect" do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
"ice".freeze
|
||||
end
|
||||
end
|
||||
weird.new.ai(:plain => false).should == "ice"
|
||||
end
|
||||
|
||||
# See https://github.com/michaeldv/awesome_print/issues/35
|
||||
it "handle array grep when pattern contains / chapacter" do
|
||||
hash = { "1/x" => 1, "2//x" => :"2" }
|
||||
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
||||
grepped.ai(:plain => true, :multiline => false).should == '[ "1", "2" ]'
|
||||
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
|
||||
self.stub!(:puts)
|
||||
(ap object).should == object
|
||||
end
|
||||
|
||||
# Require different file name this time (lib/ap.rb vs. lib/awesome_print).
|
||||
it "several require 'awesome_print' should do no harm" do
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../lib/ap')
|
||||
lambda { rand.ai }.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "HTML output" do
|
||||
it "wraps ap output with plain <pre> tag" do
|
||||
markup = rand
|
||||
markup.ai(:html => true, :plain => true).should == "<pre>#{markup}</pre>"
|
||||
end
|
||||
|
||||
it "wraps ap output with <pre> tag with colorized <kbd>" do
|
||||
markup = rand
|
||||
markup.ai(:html => true).should == %Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|
|
||||
end
|
||||
|
||||
it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
|
||||
markup = [ 1, :two, "three" ]
|
||||
markup.ai(:html => true).should == <<-EOS.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd><pre><kbd style="color:blue">1</kbd></pre>,
|
||||
<kbd style="color:white">[1] </kbd><pre><kbd style="color:darkcyan">:two</kbd></pre>,
|
||||
<kbd style="color:white">[2] </kbd><pre><kbd style="color:brown">"three"</kbd></pre>
|
||||
]</pre>
|
||||
EOS
|
||||
end
|
||||
|
||||
it "encodes HTML entities (plain)" do
|
||||
markup = ' &<hello>'
|
||||
markup.ai(:html => true, :plain => true).should == '<pre>" &<hello>"</pre>'
|
||||
end
|
||||
|
||||
it "encodes HTML entities (color)" do
|
||||
markup = ' &<hello>'
|
||||
markup.ai(:html => true).should == '<pre><kbd style="color:brown">" &<hello>"</kbd></pre>'
|
||||
end
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Inherited from standard Ruby classes" do
|
||||
after do
|
||||
|
|
|
@ -411,7 +411,7 @@ describe "Methods arrays" do
|
|||
def self.m_two; end
|
||||
end
|
||||
|
||||
out = Hello.methods.grep(/^m_(.+)$/) { $1.to_sym }
|
||||
out = Hello.methods.sort.grep(/^m_(.+)$/) { $1.to_sym }
|
||||
out.should == [:one, :two]
|
||||
end
|
||||
|
||||
|
|
89
spec/misc_specs.rb
Normal file
89
spec/misc_specs.rb
Normal file
|
@ -0,0 +1,89 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
describe "AwesomePrint" do
|
||||
before do
|
||||
stub_dotfile!
|
||||
end
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
describe "Misc" do
|
||||
it "handle weird objects that return nil on inspect" do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
nil
|
||||
end
|
||||
end
|
||||
weird.new.ai(:plain => true).should == ''
|
||||
end
|
||||
|
||||
it "handle frozen object.inspect" do
|
||||
weird = Class.new do
|
||||
def inspect
|
||||
"ice".freeze
|
||||
end
|
||||
end
|
||||
weird.new.ai(:plain => false).should == "ice"
|
||||
end
|
||||
|
||||
# See https://github.com/michaeldv/awesome_print/issues/35
|
||||
it "handle array grep when pattern contains / chapacter" do
|
||||
hash = { "1/x" => 1, "2//x" => :"2" }
|
||||
grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 }
|
||||
grepped.ai(:plain => true, :multiline => false).should == '[ "1", "2" ]'
|
||||
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
|
||||
self.stub!(:puts)
|
||||
(ap object).should == object
|
||||
end
|
||||
|
||||
# Require different file name this time (lib/ap.rb vs. lib/awesome_print).
|
||||
it "several require 'awesome_print' should do no harm" do
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../lib/ap')
|
||||
lambda { rand.ai }.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "HTML output" do
|
||||
it "wraps ap output with plain <pre> tag" do
|
||||
markup = rand
|
||||
markup.ai(:html => true, :plain => true).should == "<pre>#{markup}</pre>"
|
||||
end
|
||||
|
||||
it "wraps ap output with <pre> tag with colorized <kbd>" do
|
||||
markup = rand
|
||||
markup.ai(:html => true).should == %Q|<pre><kbd style="color:blue">#{markup}</kbd></pre>|
|
||||
end
|
||||
|
||||
it "wraps multiline ap output with <pre> tag with colorized <kbd>" do
|
||||
markup = [ 1, :two, "three" ]
|
||||
markup.ai(:html => true).should == <<-EOS.strip
|
||||
<pre>[
|
||||
<kbd style="color:white">[0] </kbd><pre><kbd style="color:blue">1</kbd></pre>,
|
||||
<kbd style="color:white">[1] </kbd><pre><kbd style="color:darkcyan">:two</kbd></pre>,
|
||||
<kbd style="color:white">[2] </kbd><pre><kbd style="color:brown">"three"</kbd></pre>
|
||||
]</pre>
|
||||
EOS
|
||||
end
|
||||
|
||||
it "encodes HTML entities (plain)" do
|
||||
markup = ' &<hello>'
|
||||
markup.ai(:html => true, :plain => true).should == '<pre>" &<hello>"</pre>'
|
||||
end
|
||||
|
||||
it "encodes HTML entities (color)" do
|
||||
markup = ' &<hello>'
|
||||
markup.ai(:html => true).should == '<pre><kbd style="color:brown">" &<hello>"</kbd></pre>'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue