OSDN Git Service

add rspec-rails
[praisedb/praisedb.git] / vendor / plugins / rspec-rails / lib / spec / rails / example / assigns_hash_proxy.rb
1 module Spec
2   module Rails
3     module Example
4       class AssignsHashProxy #:nodoc:
5         def initialize(example_group, &block)
6           @target = block.call
7           @example_group = example_group
8         end
9
10         def [](key)
11           return false if false == assigns[key] || false == assigns[key.to_s]
12           assigns[key] || assigns[key.to_s] || @target.instance_variable_get("@#{key}")
13         end
14
15         def []=(key, val)
16           @target.instance_variable_set("@#{key}", val)
17         end
18
19         def delete(key)
20           assigns.delete(key.to_s)
21           @target.instance_variable_set("@#{key}", nil)
22         end
23
24         def each(&block)
25           assigns.each &block
26         end
27
28         def has_key?(key)
29           assigns.key?(key.to_s)
30         end
31
32         protected
33         def assigns
34           @example_group.orig_assigns
35         end
36       end
37     end
38   end
39 end