fakes 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,15 @@ module Fakes
3
3
  attr_accessor :original,:replacement
4
4
  attr_reader :klass
5
5
 
6
- def initialize(klass,replacement,options ={})
7
- @klass = klass.to_s.to_sym
6
+ def initialize(fully_qualified_klass,replacement,options ={})
7
+ klass_parts = fully_qualified_klass.to_s
8
+ parts = klass_parts.split('::')
9
+ the_module = parts.count == 1 ? Object : eval(parts.slice(0,parts.count - 1).join('::'))
10
+ @klass = parts[parts.count - 1].to_s.to_sym
11
+
8
12
  @replacement = replacement
9
- @remove_strategy = options.fetch(:remove_strategy,lambda{|klass_symbol| Object.send(:remove_const,klass_symbol)})
10
- @set_strategy = options.fetch(:set_strategy,lambda{|klass_symbol,new_value| Object.const_set(klass_symbol,new_value)})
13
+ @remove_strategy = options.fetch(:remove_strategy,lambda{|klass_symbol| the_module.send(:remove_const,klass_symbol)})
14
+ @set_strategy = options.fetch(:set_strategy,lambda{|klass_symbol,new_value| the_module.const_set(klass_symbol,new_value)})
11
15
  end
12
16
 
13
17
  def initiate
data/lib/core/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fakes
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -8,12 +8,12 @@ module Fakes
8
8
  let(:sut){ClassSwap.new(MyClass,Object.new)}
9
9
 
10
10
  it "should store the symbol of the class it is going to replace" do
11
- sut.klass.should == MyClass.to_s.to_sym
11
+ sut.klass.should == :MyClass
12
12
  end
13
13
  end
14
14
  context "when initiated" do
15
15
  let(:replacement){Object.new}
16
- let(:the_sym){MyClass.to_s.to_sym}
16
+ let(:the_sym){:MyClass}
17
17
  let(:remove_strategy){Proc.new do|klass_to_remove|
18
18
  @klass_to_remove = klass_to_remove
19
19
  MyClass
@@ -39,7 +39,7 @@ module Fakes
39
39
  end
40
40
  context "when reset" do
41
41
  let(:original){MyClass}
42
- let(:the_sym){MyClass.to_s.to_sym}
42
+ let(:the_sym){:MyClass}
43
43
  let(:replacement){Object.new}
44
44
  let(:remove_strategy){Proc.new do|klass_to_remove|
45
45
  @klass_to_remove = klass_to_remove
@@ -1,5 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
+ module SomeModule
4
+ module NestedModule
5
+ class AClassInANestedModule
6
+ end
7
+ end
8
+ class ClassInAModule
9
+ end
10
+ end
3
11
  module Fakes
4
12
  class SomeClass
5
13
  def self.calculate
@@ -94,6 +102,17 @@ module Fakes
94
102
  ClassSwaps.instance.reset
95
103
  Dir.should_not == replacement
96
104
  end
105
+ it 'should be able to swap class values in another module' do
106
+ ClassSwaps.instance.add_fake_for(SomeModule::ClassInAModule,replacement)
107
+ SomeModule::ClassInAModule.should == replacement
108
+ ClassSwaps.instance.reset
109
+ SomeModule::ClassInAModule.should_not == replacement
110
+
111
+ ClassSwaps.instance.add_fake_for(SomeModule::NestedModule::AClassInANestedModule,replacement)
112
+ SomeModule::NestedModule::AClassInANestedModule.should == replacement
113
+ ClassSwaps.instance.reset
114
+ SomeModule::NestedModule::AClassInANestedModule.should_not == replacement
115
+ end
97
116
  end
98
117
  end
99
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-12 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec