rr 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.3.6
2
+ - Fixed [#12765] Issues with ObjectSpace._id2ref
3
+
1
4
  * 0.3.5
2
5
  - trim_backtrace is only set for Test::Unit
3
6
 
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ def run_suite
25
25
  end
26
26
 
27
27
  PKG_NAME = "rr"
28
- PKG_VERSION = "0.3.5"
28
+ PKG_VERSION = "0.3.6"
29
29
  PKG_FILES = FileList[
30
30
  '[A-Z]*',
31
31
  '*.rb',
@@ -5,7 +5,7 @@ class ExampleSuite
5
5
  def run
6
6
  options = ::Spec::Runner::OptionParser.new.parse(ARGV.dup, STDERR, STDOUT, false)
7
7
  $behaviour_runner = options.create_behaviour_runner
8
-
8
+
9
9
  require_specs
10
10
 
11
11
  puts "Running Example Suite"
@@ -0,0 +1,86 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ describe HashWithObjectIdKey, "#[] and #[]=" do
5
+ it "stores object via object id" do
6
+ hash = HashWithObjectIdKey.new
7
+ array_1 = []
8
+ hash[array_1] = 1
9
+ array_2 = []
10
+ hash[array_2] = 2
11
+
12
+ hash[array_1].should_not == hash[array_2]
13
+ end
14
+
15
+ it "stores the passed in object" do
16
+ hash = HashWithObjectIdKey.new
17
+ obj = Object.new
18
+ hash[obj] = 1
19
+ hash.instance_eval {@keys}.should == {obj.__id__ => obj}
20
+ end
21
+ end
22
+
23
+ describe HashWithObjectIdKey, "#each" do
24
+ it "iterates through the items in the hash" do
25
+ hash = HashWithObjectIdKey.new
26
+ hash['one'] = 1
27
+ hash['two'] = 2
28
+
29
+ keys = []
30
+ values = []
31
+ hash.each do |key, value|
32
+ keys << key
33
+ values << value
34
+ end
35
+
36
+ keys.sort.should == ['one', 'two']
37
+ values.sort.should == [1, 2]
38
+ end
39
+ end
40
+
41
+ describe HashWithObjectIdKey, "#delete" do
42
+ before do
43
+ @hash = HashWithObjectIdKey.new
44
+ @key = Object.new
45
+ @hash[@key] = 1
46
+ end
47
+
48
+ it "removes the object from the hash" do
49
+ @hash.delete(@key)
50
+ @hash[@key].should == {}
51
+ end
52
+
53
+ it "removes the object from the keys hash" do
54
+ @hash.delete(@key)
55
+ @hash.instance_eval {@keys}.should == {}
56
+ end
57
+ end
58
+
59
+ describe HashWithObjectIdKey, "#keys" do
60
+ before do
61
+ @hash = HashWithObjectIdKey.new
62
+ @key = Object.new
63
+ @hash[@key] = 1
64
+ end
65
+
66
+ it "returns an array of the keys" do
67
+ @hash.keys.should == [@key]
68
+ end
69
+ end
70
+
71
+ describe HashWithObjectIdKey, "#include?" do
72
+ before do
73
+ @hash = HashWithObjectIdKey.new
74
+ @key = Object.new
75
+ @hash[@key] = 1
76
+ end
77
+
78
+ it "returns true when the key is in the Hash" do
79
+ @hash.should include(@key)
80
+ end
81
+
82
+ it "returns false when the key is not in the Hash" do
83
+ @hash.should_not include(Object.new)
84
+ end
85
+ end
86
+ end
data/lib/rr.rb CHANGED
@@ -1,5 +1,3 @@
1
- require "forwardable"
2
-
3
1
  require "rr/errors/rr_error"
4
2
  require "rr/errors/scenario_definition_error"
5
3
  require "rr/errors/scenario_not_found_error"
@@ -1,28 +1,37 @@
1
1
  module RR
2
2
  class HashWithObjectIdKey < ::Hash
3
+ def initialize
4
+ @keys = {}
5
+ super do |hash, subject_object|
6
+ hash.set_with_object_id(subject_object, {})
7
+ end
8
+ end
9
+
3
10
  alias_method :get_with_object_id, :[]
4
11
  def [](key)
12
+ @keys[key.__id__] = key
5
13
  super(key.__id__)
6
14
  end
7
15
 
8
16
  alias_method :set_with_object_id, :[]=
9
17
  def []=(key, value)
18
+ @keys[key.__id__] = key
10
19
  super(key.__id__, value)
11
20
  end
12
21
 
13
22
  def each
14
23
  super do |object_id, value|
15
- yield ObjectSpace._id2ref(object_id), value
24
+ yield @keys[object_id], value
16
25
  end
17
26
  end
18
27
 
19
28
  def delete(key)
29
+ @keys.delete(key.__id__)
20
30
  super(key.__id__)
21
31
  end
22
32
 
23
33
  def keys
24
- raw_keys = super
25
- raw_keys.collect {|raw_key| ObjectSpace._id2ref(raw_key)}
34
+ @keys.values
26
35
  end
27
36
 
28
37
  def include?(key)
data/lib/rr/space.rb CHANGED
@@ -18,9 +18,7 @@ module RR
18
18
  attr_reader :doubles, :ordered_scenarios
19
19
  attr_accessor :trim_backtrace
20
20
  def initialize
21
- @doubles = HashWithObjectIdKey.new do |hash, subject_object|
22
- hash.set_with_object_id(subject_object, HashWithObjectIdKey.new)
23
- end
21
+ @doubles = HashWithObjectIdKey.new
24
22
  @ordered_scenarios = []
25
23
  @trim_backtrace = false
26
24
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.5
7
- date: 2007-07-29 00:00:00 -07:00
6
+ version: 0.3.6
7
+ date: 2007-08-01 00:00:00 -07:00
8
8
  summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
9
9
  require_paths:
10
10
  - lib
@@ -95,6 +95,7 @@ files:
95
95
  - examples/rr/space/space_create_example.rb
96
96
  - examples/rr/space/space_helper.rb
97
97
  - examples/rr/space/space_example.rb
98
+ - examples/rr/space/hash_with_object_id_key_example.rb
98
99
  - examples/rr/space/space_register_example.rb
99
100
  - examples/rr/expectations/is_a_argument_equality_expectation_example.rb
100
101
  - examples/rr/expectations/any_argument_expectation_example.rb