Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/activesupport/test/option_merger_test.rb

Revision 8563, 1.5 kB (checked in by bitsweat, 8 months ago)

require abstract_unit directly since test is in load path

Line 
1 require 'abstract_unit'
2
3 class OptionMergerTest < Test::Unit::TestCase
4   def setup
5     @options = {:hello => 'world'}
6   end
7
8   def test_method_with_options_merges_options_when_options_are_present
9     local_options = {:cool => true}
10
11     with_options(@options) do |o|
12       assert_equal local_options, method_with_options(local_options)
13       assert_equal @options.merge(local_options),
14         o.method_with_options(local_options)
15     end
16   end
17
18   def test_method_with_options_appends_options_when_options_are_missing
19     with_options(@options) do |o|
20       assert_equal Hash.new, method_with_options
21       assert_equal @options, o.method_with_options
22     end
23   end
24
25   def test_method_with_options_allows_to_overwrite_options
26     local_options = {:hello => 'moon'}
27     assert_equal @options.keys, local_options.keys
28
29     with_options(@options) do |o|
30       assert_equal local_options, method_with_options(local_options)
31       assert_equal @options.merge(local_options),
32         o.method_with_options(local_options)
33       assert_equal local_options, o.method_with_options(local_options)
34     end
35     with_options(local_options) do |o|
36       assert_equal local_options.merge(@options),
37         o.method_with_options(@options)
38     end
39   end
40
41   # Needed when counting objects with the ObjectSpace
42   def test_option_merger_class_method
43     assert_equal ActiveSupport::OptionMerger, ActiveSupport::OptionMerger.new('', '').class
44   end
45
46   private
47     def method_with_options(options = {})
48       options
49     end
50 end
Note: See TracBrowser for help on using the browser.