hirb 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,12 @@
1
+ == 0.3.2
2
+ * Added irb autocompletions for bond.
3
+ * Fixed tests for ruby 1.9.
4
+ * Changed tests to use bacon.
5
+ * Removed jeweler in Rakefile and pointless $LOAD_PATH manipulation.
6
+
1
7
  == 0.3.1
2
- * Bug fix on DynamicView.class_to_method to allow overrides of default views
3
- * Modified mongo_mapper view to have _id first
8
+ * Bug fix on DynamicView.class_to_method to allow overrides of default views.
9
+ * Modified mongo_mapper view to have _id first.
4
10
 
5
11
  == 0.3.0
6
12
  * Added dynamic views.
data/Rakefile CHANGED
@@ -1,53 +1,35 @@
1
1
  require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
- begin
5
- require 'rcov/rcovtask'
2
+ require 'fileutils'
6
3
 
7
- Rcov::RcovTask.new do |t|
8
- t.libs << 'test'
9
- t.test_files = FileList['test/**/*_test.rb']
10
- t.rcov_opts = ["-T -x '/Library/Ruby/*'"]
11
- t.verbose = true
12
- end
13
- rescue LoadError
14
- puts "Rcov not available. Install it for rcov-related tasks with: sudo gem install rcov"
4
+ def gemspec
5
+ @gemspec ||= eval(File.read('gemspec'), binding, 'gemspec')
15
6
  end
16
7
 
17
- begin
18
- require 'jeweler'
19
- require File.dirname(__FILE__) + "/lib/hirb/version"
8
+ desc "Build the gem"
9
+ task :gem=>:gemspec do
10
+ sh "gem build gemspec"
11
+ FileUtils.mkdir_p 'pkg'
12
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
13
+ end
20
14
 
21
- Jeweler::Tasks.new do |s|
22
- s.name = "hirb"
23
- s.version = Hirb::VERSION
24
- s.summary = "A mini view framework for console/irb that's easy to use, even while under its influence."
25
- s.description = "Hirb currently provides a mini view framework for console applications, designed to improve irb's default output. Hirb improves console output by providing a smart pager and auto-formatting output. The smart pager detects when an output exceeds a screenful and thus only pages output as needed. Auto-formatting adds a view to an output's class. This is helpful in separating views from content (MVC anyone?). The framework encourages reusing views by letting you package them in classes and associate them with any number of output classes."
26
- s.email = "gabriel.horner@gmail.com"
27
- s.homepage = "http://tagaholic.me/hirb/"
28
- s.authors = ["Gabriel Horner"]
29
- s.rubyforge_project = 'tagaholic'
30
- s.has_rdoc = true
31
- s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
32
- s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
33
- end
15
+ desc "Install the gem locally"
16
+ task :install => :gem do
17
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
18
+ end
34
19
 
35
- rescue LoadError
36
- puts "Jeweler not available. Install it for jeweler-related tasks with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
+ desc "Generate the gemspec"
21
+ task :generate do
22
+ puts gemspec.to_ruby
37
23
  end
38
24
 
39
- Rake::TestTask.new do |t|
40
- t.libs << 'lib'
41
- t.pattern = 'test/**/*_test.rb'
42
- t.verbose = false
25
+ desc "Validate the gemspec"
26
+ task :gemspec do
27
+ gemspec.validate
43
28
  end
44
29
 
45
- Rake::RDocTask.new do |rdoc|
46
- rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = 'test'
48
- rdoc.options << '--line-numbers' << '--inline-source'
49
- rdoc.rdoc_files.include('README*')
50
- rdoc.rdoc_files.include('lib/**/*.rb')
30
+ desc 'Run tests'
31
+ task :test do |t|
32
+ sh 'bacon -q -Ilib -I. test/*_test.rb'
51
33
  end
52
34
 
53
- task :default => :test
35
+ task :default => :test
data/gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless Object.const_defined?(:Gem)
3
+ require File.dirname(__FILE__) + "/lib/hirb/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hirb"
7
+ s.version = Hirb::VERSION
8
+ s.authors = ["Gabriel Horner"]
9
+ s.email = "gabriel.horner@gmail.com"
10
+ s.homepage = "http://tagaholic.me/hirb/"
11
+ s.summary = "A mini view framework for console/irb that's easy to use, even while under its influence."
12
+ s.description = "Hirb currently provides a mini view framework for console applications, designed to improve irb's default output. Hirb improves console output by providing a smart pager and auto-formatting output. The smart pager detects when an output exceeds a screenful and thus only pages output as needed. Auto-formatting adds a view to an output's class. This is helpful in separating views from content (MVC anyone?). The framework encourages reusing views by letting you package them in classes and associate them with any number of output classes."
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.rubyforge_project = 'tagaholic'
15
+ s.add_development_dependency 'bacon'
16
+ s.add_development_dependency 'mocha'
17
+ s.add_development_dependency 'mocha-on-bacon'
18
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c}]) + %w{Rakefile gemspec}
19
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
20
+ end
@@ -0,0 +1,14 @@
1
+ complete(:methods=>%w{Hirb::View.enable Hirb.enable}) {
2
+ %w{config_file output_method output width height formatter pager pager_command}
3
+ }
4
+ complete(:methods=>%w{Hirb::Helpers::Table.render table}) {
5
+ %w{fields headers max_fields max_width resize number change_fields}+
6
+ %w{filters header_filter filter_any filter_classes vertical all_fields}+
7
+ %w{description escape_special_chars table_class hide_empty}
8
+ }
9
+ complete(:method=>"Hirb::Helpers::Tree.render") {
10
+ %w{type validate indent limit description multi_line_nodes value_method children_method}
11
+ }
12
+ complete(:methods=>%w{Hirb::Menu.render menu}) {
13
+ %w{helper_class prompt ask directions readline two_d default_field action multi_action action_object command}
14
+ }
@@ -1,6 +1,3 @@
1
- current_dir = File.dirname(__FILE__)
2
- $:.unshift(current_dir) unless $:.include?(current_dir) || $:.include?(File.expand_path(current_dir))
3
-
4
1
  # Needed by Hirb::String to handle multibyte characters
5
2
  $KCODE = 'u' if RUBY_VERSION < '1.9'
6
3
 
@@ -164,7 +164,7 @@ module Hirb
164
164
  rows = filter_values(rows)
165
165
  rows.each_with_index {|e,i| e[:hirb_number] = (i + 1).to_s} if @options[:number]
166
166
  deleted_callbacks = Array(@options[:delete_callbacks]).map {|e| "#{e}_callback" }
167
- (methods.grep(/_callback$/) - deleted_callbacks).sort.each do |meth|
167
+ (methods.grep(/_callback$/).map {|e| e.to_s} - deleted_callbacks).sort.each do |meth|
168
168
  rows = send(meth, rows, @options.dup)
169
169
  end
170
170
  validate_values(rows)
@@ -1,3 +1,3 @@
1
1
  module Hirb
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -1,32 +1,30 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class Hirb::Helpers::AutoTableTest < Test::Unit::TestCase
4
- context "auto table" do
5
- test "converts nonarrays to arrays and renders" do
6
- require 'set'
7
- expected_table = <<-TABLE.unindent
8
- +-------+
9
- | value |
10
- +-------+
11
- | 1 |
12
- | 2 |
13
- | 3 |
14
- +-------+
15
- 3 rows in set
16
- TABLE
17
- Hirb::Helpers::AutoTable.render(::Set.new([1,2,3])).should == expected_table
18
- end
3
+ describe "auto table" do
4
+ it "converts nonarrays to arrays and renders" do
5
+ require 'set'
6
+ expected_table = <<-TABLE.unindent
7
+ +-------+
8
+ | value |
9
+ +-------+
10
+ | 1 |
11
+ | 2 |
12
+ | 3 |
13
+ +-------+
14
+ 3 rows in set
15
+ TABLE
16
+ Helpers::AutoTable.render(::Set.new([1,2,3])).should == expected_table
17
+ end
19
18
 
20
- test "renders hash" do
21
- expected_table = <<-TABLE.unindent
22
- +---+-------+
23
- | 0 | 1 |
24
- +---+-------+
25
- | a | 12345 |
26
- +---+-------+
27
- 1 row in set
28
- TABLE
29
- Hirb::Helpers::AutoTable.render({:a=>12345}).should == expected_table
30
- end
19
+ it "renders hash" do
20
+ expected_table = <<-TABLE.unindent
21
+ +---+-------+
22
+ | 0 | 1 |
23
+ +---+-------+
24
+ | a | 12345 |
25
+ +---+-------+
26
+ 1 row in set
27
+ TABLE
28
+ Helpers::AutoTable.render({:a=>12345}).should == expected_table
31
29
  end
32
30
  end
@@ -0,0 +1,26 @@
1
+ module BaconExtensions
2
+ def self.included(mod)
3
+ mod.module_eval do
4
+ # nested context methods automatically inherit methods from parent contexts
5
+ def describe(*args, &block)
6
+ context = Bacon::Context.new(args.join(' '), &block)
7
+ (parent_context = self).methods(false).each {|e|
8
+ class<<context; self end.send(:define_method, e) {|*args| parent_context.send(e, *args)}
9
+ }
10
+ @before.each { |b| context.before(&b) }
11
+ @after.each { |b| context.after(&b) }
12
+ context.run
13
+ end
14
+ end
15
+ end
16
+
17
+ def xit(*args); end
18
+ def xdescribe(*args); end
19
+ def before_all; yield; end
20
+ def after_all; yield; end
21
+ def assert(description, &block)
22
+ it(description) do
23
+ block.call.should == true
24
+ end
25
+ end
26
+ end
@@ -1,12 +1,10 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class Hirb::ConsoleTest < Test::Unit::TestCase
4
- context "parse_input" do
5
- test "config is set if it wasn't before" do
6
- reset_config
7
- Hirb::View.expects(:render_output)
8
- Hirb::Console.render_output('blah')
9
- Hirb::View.config.is_a?(Hash).should == true
10
- end
3
+ describe "parse_input" do
4
+ it "config is set if it wasn't before" do
5
+ reset_config
6
+ View.expects(:render_output)
7
+ Console.render_output('blah')
8
+ View.config.is_a?(Hash).should == true
11
9
  end
12
- end
10
+ end
@@ -1,100 +1,94 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- module Hirb
4
- class DynamicViewTest < Test::Unit::TestCase
5
- def output_expects(output, expects)
6
- Helpers::ObjectTable.expects(:render).with(output, expects)
7
- Helpers::AutoTable.render(output)
8
- end
9
- after(:all) { Formatter.dynamic_config = {} }
10
-
11
- context "add" do
12
- before(:all) { View.load_config }
3
+ describe "DynamicView" do
4
+ def output_expects(output, expects)
5
+ Helpers::ObjectTable.expects(:render).with(output, expects)
6
+ Helpers::AutoTable.render(output)
7
+ end
13
8
 
14
- test "raises error if no :helper option" do
15
- assert_raises(ArgumentError) {
16
- Hirb.add_dynamic_view 'Blah', {}
17
- }.message.should =~ /:helper.*required/
18
- end
9
+ describe "add" do
10
+ before_all { View.load_config }
19
11
 
20
- test "raises error if :helper option not a dynamic_view module" do
21
- assert_raises(ArgumentError) {
22
- Hirb.add_dynamic_view('Blah', :helper=>:table) {|obj| }
23
- }.message.should =~ /:helper.*must/
24
- end
12
+ it "raises error if no :helper option" do
13
+ lambda { Hirb.add_dynamic_view 'Blah', {} }.should.raise(ArgumentError).
14
+ message.should =~ /:helper.*required/
15
+ end
25
16
 
26
- test "raises error if views module not a module" do
27
- assert_raises(ArgumentError) {
28
- Hirb.add_dynamic_view 'Blah', :helper=>:auto_table
29
- }.message.should =~ /must be a module/
30
- end
17
+ it "raises error if :helper option not a dynamic_view module" do
18
+ lambda { Hirb.add_dynamic_view('Blah', :helper=>:table) {|obj| } }.
19
+ should.raise(ArgumentError).message.should =~ /:helper.*must/
20
+ end
31
21
 
32
- test "adds a view with block" do
33
- Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
34
- {:fields=>obj.class::DAYNAMES}
35
- end
36
- output_expects [Date.new], :fields=>Date::DAYNAMES
37
- end
22
+ it "raises error if views module not a module" do
23
+ lambda { Hirb.add_dynamic_view 'Blah', :helper=>:auto_table }.should.raise(ArgumentError).
24
+ message.should =~ /must be a module/
25
+ end
38
26
 
39
- test "when adding views with a block, second view for same class overrides first one" do
40
- Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
41
- {:fields=>obj.class::DAYNAMES}
42
- end
43
- Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
44
- {:fields=>[:blah]}
45
- end
46
- output_expects [Date.new], :fields=>[:blah]
27
+ it "adds a view with block" do
28
+ Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
29
+ {:fields=>obj.class::DAYNAMES}
47
30
  end
31
+ output_expects [Date.new], :fields=>Date::DAYNAMES
48
32
  end
49
33
 
50
- test "class_to_method and method_to_class convert to each other" do
51
- ["DBI::Row", "Hirb::View"].each do |e|
52
- Helpers::AutoTable.method_to_class(DynamicView.class_to_method(e).downcase).should == e
34
+ it "when adding views with a block, second view for same class overrides first one" do
35
+ Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
36
+ {:fields=>obj.class::DAYNAMES}
37
+ end
38
+ Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
39
+ {:fields=>[:blah]}
53
40
  end
41
+ output_expects [Date.new], :fields=>[:blah]
54
42
  end
43
+ end
55
44
 
56
- test "class_to_method converts correctly" do
57
- DynamicView.class_to_method("DBI::Row").should == 'd_b_i__row_view'
45
+ it "class_to_method and method_to_class convert to each other" do
46
+ ["DBI::Row", "Hirb::View"].each do |e|
47
+ Helpers::AutoTable.method_to_class(DynamicView.class_to_method(e).downcase).should == e
58
48
  end
49
+ end
59
50
 
60
- context "dynamic_view" do
61
- def define_view(mod_name= :Blah, &block)
62
- mod = Views.const_set(mod_name, Module.new)
63
- mod_block = block_given? ? block : lambda {|obj| {:fields=>obj.class::DAYNAMES}}
64
- mod.send(:define_method, :date_view, mod_block)
65
- Hirb.add_dynamic_view mod, :helper=>:auto_table
66
- end
51
+ it "class_to_method converts correctly" do
52
+ DynamicView.class_to_method("DBI::Row").should == 'd_b_i__row_view'
53
+ end
67
54
 
68
- before(:all) { View.load_config }
69
- before(:each) { Formatter.dynamic_config = {} }
70
- after(:each) { Views.send(:remove_const, :Blah) }
71
- after(:all) { reset_config }
55
+ describe "dynamic_view" do
56
+ def define_view(mod_name= :Blah, &block)
57
+ mod = Views.const_set(mod_name, Module.new)
58
+ mod_block = block_given? ? block : lambda {|obj| {:fields=>obj.class::DAYNAMES}}
59
+ mod.send(:define_method, :date_view, mod_block)
60
+ Hirb.add_dynamic_view mod, :helper=>:auto_table
61
+ end
72
62
 
73
- test "sets a view's options" do
74
- define_view
75
- output_expects [Date.new], :fields=>Date::DAYNAMES
76
- end
63
+ before_all { View.load_config }
64
+ before { Formatter.dynamic_config = {} }
65
+ after { Views.send(:remove_const, :Blah) }
77
66
 
78
- test "does override existing formatter dynamic_config" do
79
- Formatter.dynamic_config["Date"] = {:class=>Helpers::Table}
80
- define_view
81
- Formatter.dynamic_config["Date"].should == {:class=>Hirb::Helpers::AutoTable, :ancestor=>true}
82
- end
67
+ it "sets a view's options" do
68
+ define_view
69
+ output_expects [Date.new], :fields=>Date::DAYNAMES
70
+ end
83
71
 
84
- test "raises a readable error when error occurs in a view" do
85
- define_view {|obj| raise 'blah' }
86
- assert_raises(RuntimeError) {
87
- Helpers::AutoTable.render([Date.new])
88
- }.message.should =~ /'Date'.*date_view.*\nblah/
89
- end
72
+ it "does override existing formatter dynamic_config" do
73
+ Formatter.dynamic_config["Date"] = {:class=>Helpers::Table}
74
+ define_view
75
+ Formatter.dynamic_config["Date"].should == {:class=>Hirb::Helpers::AutoTable, :ancestor=>true}
76
+ end
77
+
78
+ it "raises a readable error when error occurs in a view" do
79
+ define_view {|obj| raise 'blah' }
80
+ lambda { Helpers::AutoTable.render([Date.new]) }.should.raise(RuntimeError).
81
+ message.should =~ /'Date'.*date_view.*\nblah/
82
+ end
90
83
 
91
- test "another view can reuse an old view's options" do
92
- define_view
93
- define_view(:Blah2) do |obj|
94
- {:fields=>obj.class::DAYNAMES + ['blah']}
95
- end
96
- output_expects [Date.new], :fields=>(Date::DAYNAMES + ['blah'])
84
+ it "another view can reuse an old view's options" do
85
+ define_view
86
+ define_view(:Blah2) do |obj|
87
+ {:fields=>obj.class::DAYNAMES + ['blah']}
97
88
  end
89
+ output_expects [Date.new], :fields=>(Date::DAYNAMES + ['blah'])
98
90
  end
91
+ after_all { reset_config }
99
92
  end
100
- end
93
+ after_all { Formatter.dynamic_config = {} }
94
+ end
@@ -1,45 +1,48 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- module Hirb
4
- class FormatterTest < Test::Unit::TestCase
3
+ describe "Formatter" do
5
4
  def set_formatter(hash={})
6
5
  @formatter = Formatter.new(hash)
7
6
  end
8
7
 
9
- context "klass_config" do
10
- test "recursively merges ancestor options" do
11
- set_formatter "String"=>{:args=>[1,2], :options=>{:fields=>[:to_s]}},
8
+ describe "klass_config" do
9
+ it "recursively merges ancestor options" do
10
+ @formatter = set_formatter "String"=>{:args=>[1,2], :options=>{:fields=>[:to_s]}},
12
11
  "Object"=>{:method=>:object_output, :ancestor=>true, :options=>{:vertical=>true}},
13
12
  "Kernel"=>{:method=>:default_output}
14
13
  expected_result = {:method=>:object_output, :args=>[1, 2], :ancestor=>true, :options=>{:fields=>[:to_s], :vertical=>true}}
15
14
  @formatter.klass_config(::String).should == expected_result
16
15
  end
17
16
 
18
- test "doesn't merge ancestor options" do
19
- set_formatter "String"=>{:args=>[1,2]}, "Object"=>{:method=>:object_output}, "Kernel"=>{:method=>:default_output}
17
+ it "doesn't merge ancestor options" do
18
+ @formatter = set_formatter "String"=>{:args=>[1,2]}, "Object"=>{:method=>:object_output},
19
+ "Kernel"=>{:method=>:default_output}
20
20
  @formatter.klass_config(::String).should == {:args=>[1, 2]}
21
21
  end
22
22
 
23
- test "returns hash when nothing found" do
23
+ it "returns hash when nothing found" do
24
24
  set_formatter.klass_config(::String).should == {}
25
25
  end
26
26
 
27
- context "with dynamic_config" do
28
- after(:each) { Formatter.dynamic_config = {}}
27
+ describe "with dynamic_config" do
28
+ def set_formatter(hash={})
29
+ @formatter = Formatter.new(hash)
30
+ end
31
+ after { Formatter.dynamic_config = {}}
29
32
 
30
- test "merges ancestor options and sets local config" do
33
+ it "merges ancestor options and sets local config" do
31
34
  Formatter.dynamic_config = {"Object"=>{:method=>:blah}, "Kernel"=>{:args=>[1,2], :ancestor=>true}}
32
35
  set_formatter.klass_config(::String).should == {:args=>[1,2], :ancestor=>true}
33
36
  @formatter.config['Kernel'].should == {:args=>[1,2], :ancestor=>true}
34
37
  end
35
38
 
36
- test "uses local config over dynamic_config" do
39
+ it "uses local config over dynamic_config" do
37
40
  Formatter.dynamic_config = {"String"=>{:method=>:blah}}
38
41
  set_formatter "String"=>{:args=>[1,2]}
39
42
  @formatter.klass_config(::String).should == {:args=>[1,2]}
40
43
  end
41
44
 
42
- test "uses dynamic_config and sets local config" do
45
+ it "uses dynamic_config and sets local config" do
43
46
  Formatter.dynamic_config = {"String"=>{:method=>:blah}}
44
47
  set_formatter.klass_config(::String).should == {:method=>:blah}
45
48
  @formatter.config['String'].should == {:method=>:blah}
@@ -47,30 +50,30 @@ class FormatterTest < Test::Unit::TestCase
47
50
  end
48
51
  end
49
52
 
50
- context "formatter methods:" do
51
- before(:all) { eval "module ::Dooda; end" }
53
+ describe "formatter methods:" do
54
+ before_all { eval "module ::Dooda; end" }
52
55
 
53
- test "add_view sets formatter config" do
54
- set_formatter
56
+ it "add_view sets formatter config" do
57
+ @formatter = set_formatter
55
58
  @formatter.add_view ::Dooda, :class=>"DoodaView"
56
59
  @formatter.klass_config(::Dooda).should == {:class=>"DoodaView"}
57
60
  end
58
61
 
59
- test "add_view overwrites existing formatter config" do
60
- set_formatter "Dooda"=>{:class=>"DoodaView"}
62
+ it "add_view overwrites existing formatter config" do
63
+ @formatter = set_formatter "Dooda"=>{:class=>"DoodaView"}
61
64
  @formatter.add_view ::Dooda, :class=>"DoodaView2"
62
65
  @formatter.klass_config(::Dooda).should == {:class=>"DoodaView2"}
63
66
  end
64
67
 
65
- test "parse_console_options passes all options except for formatter options into :options" do
66
- set_formatter
68
+ it "parse_console_options passes all options except for formatter options into :options" do
69
+ @formatter = set_formatter
67
70
  options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :blah=>'blah'}
68
71
  expected_options = {:class=>'blah', :method=>'blah', :output_method=>'blah', :options=>{:blah=>'blah'}}
69
72
  @formatter.parse_console_options(options).should == expected_options
70
73
  end
71
74
  end
72
75
 
73
- context "format_output" do
76
+ describe "format_output" do
74
77
  def view_output(*args, &block); View.view_output(*args, &block); end
75
78
  def render_method(*args); View.render_method(*args); end
76
79
 
@@ -78,7 +81,7 @@ class FormatterTest < Test::Unit::TestCase
78
81
  Hirb.enable :output=>value
79
82
  end
80
83
 
81
- before(:all) {
84
+ before_all {
82
85
  eval %[module ::Commify
83
86
  def self.render(strings)
84
87
  strings = [strings] unless strings.is_a?(Array)
@@ -87,76 +90,75 @@ class FormatterTest < Test::Unit::TestCase
87
90
  end]
88
91
  reset_config
89
92
  }
90
- before(:each) { View.formatter = nil; reset_config }
91
- after(:each) { Hirb.disable }
93
+ before { View.formatter = nil; reset_config }
94
+ after { Hirb.disable }
92
95
 
93
- test "formats with method option" do
96
+ it "formats with method option" do
94
97
  eval "module ::Kernel; def commify(string); string.split('').join(','); end; end"
95
98
  enable_with_output "String"=>{:method=>:commify}
96
99
  render_method.expects(:call).with('d,u,d,e')
97
100
  view_output('dude')
98
101
  end
99
102
 
100
- test "formats with class option" do
103
+ it "formats with class option" do
101
104
  enable_with_output "String"=>{:class=>"Commify"}
102
105
  render_method.expects(:call).with('d,u,d,e')
103
106
  view_output('dude')
104
107
  end
105
108
 
106
- test "formats with class option as symbol" do
109
+ it "formats with class option as symbol" do
107
110
  enable_with_output "String"=>{:class=>:auto_table}
108
111
  Helpers::AutoTable.expects(:render)
109
112
  view_output('dude')
110
113
  end
111
114
 
112
- test "formats output array" do
115
+ it "formats output array" do
113
116
  enable_with_output "String"=>{:class=>"Commify"}
114
117
  render_method.expects(:call).with('d,u,d,e')
115
118
  view_output(['dude'])
116
119
  end
117
120
 
118
- test "formats with options option" do
121
+ it "formats with options option" do
119
122
  eval "module ::Blahify; def self.render(*args); end; end"
120
123
  enable_with_output "String"=>{:class=>"Blahify", :options=>{:fields=>%w{a b}}}
121
124
  Blahify.expects(:render).with('dude', :fields=>%w{a b})
122
125
  view_output('dude')
123
126
  end
124
127
 
125
- test "doesn't format and returns false when no format method found" do
128
+ it "doesn't format and returns false when no format method found" do
126
129
  Hirb.enable
127
130
  render_method.expects(:call).never
128
131
  view_output(Date.today).should == false
129
132
  end
130
133
 
131
- test "formats with output_method option as method" do
134
+ it "formats with output_method option as method" do
132
135
  enable_with_output 'String'=>{:class=>"Commify", :output_method=>:chop}
133
136
  render_method.expects(:call).with('d,u,d')
134
137
  view_output('dude')
135
138
  end
136
139
 
137
- test "formats with output_method option as proc" do
140
+ it "formats with output_method option as proc" do
138
141
  enable_with_output 'String'=>{:class=>"Commify", :output_method=>lambda {|e| e.chop}}
139
142
  render_method.expects(:call).with('d,u,d')
140
143
  view_output('dude')
141
144
  end
142
145
 
143
- test "formats output array with output_method option" do
146
+ it "formats output array with output_method option" do
144
147
  enable_with_output 'String'=>{:class=>"Commify", :output_method=>:chop}
145
148
  render_method.expects(:call).with("d,u,d\nm,a")
146
149
  view_output(['dude', 'man'])
147
150
  end
148
151
 
149
- test "formats with explicit class option" do
152
+ it "formats with explicit class option" do
150
153
  enable_with_output 'String'=>{:class=>"Blahify"}
151
154
  render_method.expects(:call).with('d,u,d,e')
152
155
  view_output('dude', :class=>"Commify")
153
156
  end
154
157
 
155
- test "formats with explicit options option merges with existing options" do
158
+ it "formats with explicit options option merges with existing options" do
156
159
  enable_with_output "String"=>{:class=>"Commify", :options=>{:fields=>%w{f1 f2}}}
157
160
  Commify.expects(:render).with('dude', :max_width=>10, :fields=>%w{f1 f2})
158
161
  view_output('dude', :options=>{:max_width=>10})
159
162
  end
160
163
  end
161
164
  end
162
- end