constant-redefinition 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ coverage
2
+ rdoc
3
+ doc
4
+ .yardoc
5
+ .bundle
6
+ pkg
7
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ rvm --create 1.8.7@constant-redefinition_gem
2
+ rvm --create 1.9.2@constant-redefinition_gem
3
+ rvm --create 1.9.3@constant-redefinition_gem
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ gemfile:
6
+ - Gemfile
@@ -0,0 +1,7 @@
1
+ # 1.1.0
2
+
3
+ * Support block-style setting/unsetting/resetting of constants
4
+
5
+ # 1.0.0
6
+
7
+ * Initial release
data/Gemfile CHANGED
@@ -1,12 +1,3 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "bundler", "~> 1.0.0"
10
- gem "jeweler", "~> 1.5.1"
11
- gem "rcov", ">= 0"
12
- end
3
+ gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 David Czarnecki
1
+ Copyright (c) 2010-2012 David Czarnecki
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -0,0 +1,123 @@
1
+ # constant-redefinition
2
+
3
+ Allows you to define constants if not defined on an object (or module) and redefine constants without warning.
4
+
5
+ ## Installation
6
+
7
+ `gem install constant-redefinition`
8
+
9
+ or in your `Gemfile`
10
+
11
+ ```ruby
12
+ gem 'constant-redefinition'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Define a constant if not defined:
18
+
19
+ ```ruby
20
+ define_if_not_defined(:A, 1)
21
+ => nil
22
+ A
23
+ => 1
24
+ ```
25
+
26
+ Define a constant and redefine it:
27
+
28
+ ```ruby
29
+ define_if_not_defined(:B, 1)
30
+ => nil
31
+ redefine_without_warning(:B, 2)
32
+ => 2
33
+ B
34
+ => 2
35
+ ```
36
+
37
+ Redefine a constant which should set the constant:
38
+
39
+ ```ruby
40
+ redefine_without_warning(:C, 3)
41
+ => 3
42
+ C
43
+ => 3
44
+ ```
45
+
46
+ Define a constant within a module:
47
+
48
+ ```ruby
49
+ Math.define_if_not_defined(:FOO, 2 * Math::PI)
50
+ => nil
51
+ Math::FOO
52
+ => 6.283185307179586
53
+ ```
54
+
55
+ Define and redefine a constant within a module:
56
+
57
+ ```ruby
58
+ Math.define_if_not_defined(:BAR, 3)
59
+ => nil
60
+ Math.redefine_without_warning(:BAR, 5)
61
+ => 5
62
+ Math::BAR
63
+ => 5
64
+ ```
65
+
66
+ Redefine a constant within a module which should set the constant:
67
+
68
+ ```
69
+ Math.redefine_without_warning(:AMAZING, 3)
70
+ => 3
71
+ Math::AMAZING
72
+ => 3
73
+ ```
74
+
75
+ You can also define a constant using a block which will unset the constant after the block:
76
+
77
+ ```ruby
78
+ class Freaks
79
+ GOOBLE = 'gobble'
80
+ end
81
+ => "gobble"
82
+
83
+ Freaks.define_if_not_defined(:HELLO, 'world') do
84
+ p Freaks::HELLO
85
+ end
86
+ "world"
87
+ => "world"
88
+
89
+ p Freaks::HELLO
90
+ NameError: uninitialized constant Freaks::HELLO
91
+ ```
92
+
93
+ You can also redefine a constant using a block, which will reset the constant to its original value after the block:
94
+
95
+ ```ruby
96
+ class Freaks
97
+ GOOBLE = 'gobble'
98
+ end
99
+ => "gobble"
100
+
101
+ Freaks.redefine_without_warning(:GOOBLE, 'one of us') do
102
+ p Freaks::GOOBLE
103
+ end
104
+
105
+ "one of us"
106
+ => "gobble"
107
+ ```
108
+
109
+ All credit is due to this post: http://stackoverflow.com/questions/3375360/how-to-redefine-a-ruby-constant-without-warning
110
+
111
+ ## Contributing to constant-redefinition
112
+
113
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
114
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
115
+ * Fork the project
116
+ * Start a feature/bugfix branch
117
+ * Commit and push until you are happy with your contribution
118
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
119
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
120
+
121
+ ## Copyright
122
+
123
+ Copyright (c) 2010-2012 David Czarnecki. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,53 +1,17 @@
1
- require 'rubygems'
2
1
  require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
2
+ Bundler::GemHelper.install_tasks
11
3
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "constant-redefinition"
16
- gem.homepage = "http://github.com/czarneckid/constant-redefinition"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Allows you to define constants if not defined on an object and redefine constants without warning}
19
- gem.description = %Q{Allows you to define constants if not defined on an object and redefine constants without warning}
20
- gem.email = "czarneckid@acm.org"
21
- gem.authors = ["David Czarnecki"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
4
+ require 'rspec/core/rake_task'
28
5
 
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ spec.rspec_opts = ['--backtrace']
9
+ # spec.ruby_opts = ['-w']
34
10
  end
35
11
 
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
40
- test.verbose = true
41
- end
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
12
+ task :default => :spec
48
13
 
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "constant-redefinition #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
14
+ desc "Runs tests on Ruby 1.8.7, 1.9.2 and 1.9.3"
15
+ task :test_rubies do
16
+ system "rvm 1.8.7@constant-redefinition_gem,1.9.2@constant-redefinition_gem,1.9.3@constant-redefinition_gem do rake spec"
53
17
  end
@@ -1,61 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{constant-redefinition}
8
- s.version = "1.0.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["David Czarnecki"]
12
- s.date = %q{2010-12-02}
5
+ s.name = "constant-redefinition"
6
+ s.version = "1.1.0"
7
+ s.authors = ["David Czarnecki"]
8
+ s.email = ["me@davidczarnecki.com"]
9
+ s.homepage = "https://github.com/czarneckid/constant-redefinition"
10
+ s.summary = %q{Allows you to define constants if not defined on an object and redefine constants without warning}
13
11
  s.description = %q{Allows you to define constants if not defined on an object and redefine constants without warning}
14
- s.email = %q{czarneckid@acm.org}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "constant-redefinition.gemspec",
28
- "lib/constant-redefinition.rb",
29
- "test/helper.rb",
30
- "test/test_constant-redefinition.rb"
31
- ]
32
- s.homepage = %q{http://github.com/czarneckid/constant-redefinition}
33
- s.licenses = ["MIT"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{Allows you to define constants if not defined on an object and redefine constants without warning}
37
- s.test_files = [
38
- "test/helper.rb",
39
- "test/test_constant-redefinition.rb"
40
- ]
41
12
 
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
13
+ s.rubyforge_project = "constant-redefinition"
45
14
 
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
49
- s.add_development_dependency(%q<rcov>, [">= 0"])
50
- else
51
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
53
- s.add_dependency(%q<rcov>, [">= 0"])
54
- end
55
- else
56
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
58
- s.add_dependency(%q<rcov>, [">= 0"])
59
- end
60
- end
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
61
19
 
20
+ s.add_development_dependency('rake')
21
+ s.add_development_dependency('rspec')
22
+ end
@@ -2,11 +2,25 @@ class Object
2
2
  def define_if_not_defined(const, value)
3
3
  mod = self.is_a?(Module) ? self : self.class
4
4
  mod.const_set(const, value) unless mod.const_defined?(const)
5
+ if block_given?
6
+ yield
7
+ mod.send(:remove_const, const) if mod.const_defined?(const)
8
+ end
5
9
  end
6
10
 
7
11
  def redefine_without_warning(const, value)
8
12
  mod = self.is_a?(Module) ? self : self.class
9
- mod.send(:remove_const, const) if mod.const_defined?(const)
10
- mod.const_set(const, value)
13
+ if block_given?
14
+ original_value = mod.const_get(const) if mod.const_defined?(const)
15
+ constant_was_set = mod.const_defined?(const)
16
+ mod.send(:remove_const, const) if mod.const_defined?(const)
17
+ mod.const_set(const, value)
18
+ yield
19
+ mod.send(:remove_const, const) if mod.const_defined?(const)
20
+ mod.const_set(const, original_value) if constant_was_set
21
+ else
22
+ mod.send(:remove_const, const) if mod.const_defined?(const)
23
+ mod.const_set(const, value)
24
+ end
11
25
  end
12
26
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'constant-redefinition' do
4
+ describe 'class operations' do
5
+ it 'can define a constant if not already defined' do
6
+ Object.define_if_not_defined(:A, 1)
7
+
8
+ 1.should be(Object::A)
9
+ end
10
+
11
+ it 'can re-define a constant if already defined' do
12
+ Object.define_if_not_defined(:B, 1)
13
+ 1.should be(Object::B)
14
+
15
+ Object.redefine_without_warning(:B, 2)
16
+ 2.should be(Object::B)
17
+ end
18
+
19
+ it 'can set a constant if not already defined' do
20
+ Object.redefine_without_warning(:C, 3)
21
+ 3.should be(Object::C)
22
+ end
23
+
24
+ it 'can set a constant and unset it if passed a block' do
25
+ Object.define_if_not_defined(:GOOBLE, 'gobble') do
26
+ Object.const_get(:GOOBLE).should == 'gobble'
27
+ end
28
+
29
+ lambda { Object.const_get(:GOOBLE) }.should raise_error(NameError)
30
+
31
+ Object.redefine_without_warning(:GOOBLE, 'gobble') do
32
+ Object.const_get(:GOOBLE).should == 'gobble'
33
+ end
34
+
35
+ lambda { Object.const_get(:GOOBLE) }.should raise_error(NameError)
36
+ end
37
+ end
38
+
39
+ describe 'module operations' do
40
+ it 'can define a constant if not already defined' do
41
+ Math.define_if_not_defined(:FOO, 2 * Math::PI)
42
+
43
+ (2 * Math::PI).should == Math::FOO
44
+ end
45
+
46
+ it 'can re-define a constant if already defined' do
47
+ Math.define_if_not_defined(:BAR, 3)
48
+ 3.should be(Math::BAR)
49
+
50
+ Math.redefine_without_warning(:BAR, 5)
51
+ 5.should be(Math::BAR)
52
+ end
53
+
54
+ it 'can set a constant if not already defined' do
55
+ Math.redefine_without_warning(:AMAZING, 3)
56
+ 3.should be(Math::AMAZING)
57
+ end
58
+
59
+ it 'can set a constant and unset it if passed a block' do
60
+ Math.define_if_not_defined(:GOOBLE, 'gobble') do
61
+ Math.const_get(:GOOBLE).should == 'gobble'
62
+ end
63
+
64
+ lambda { Math.const_get(:GOOBLE) }.should raise_error(NameError)
65
+
66
+ Math.redefine_without_warning(:GOOBLE, 'gobble') do
67
+ Math.const_get(:GOOBLE).should == 'gobble'
68
+ end
69
+
70
+ lambda { Math.const_get(:GOOBLE) }.should raise_error(NameError)
71
+
72
+ original_pi = Math::PI
73
+ Math.redefine_without_warning(:PI, 6) do
74
+ Math.const_get(:PI).should be(6)
75
+ end
76
+ Math.const_get(:PI).should == original_pi
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'constant-redefinition'
3
+
4
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
metadata CHANGED
@@ -1,119 +1,91 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: constant-redefinition
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - David Czarnecki
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-12-02 00:00:00 -05:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: bundler
22
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70347522369460 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 0
30
- - 0
31
- version: 1.0.0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :development
33
23
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: jeweler
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70347522369460
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70347522368680 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 5
45
- - 1
46
- version: 1.5.1
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :development
48
34
  prerelease: false
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rcov
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- version: "0"
60
- type: :development
61
- prerelease: false
62
- version_requirements: *id003
63
- description: Allows you to define constants if not defined on an object and redefine constants without warning
64
- email: czarneckid@acm.org
35
+ version_requirements: *70347522368680
36
+ description: Allows you to define constants if not defined on an object and redefine
37
+ constants without warning
38
+ email:
39
+ - me@davidczarnecki.com
65
40
  executables: []
66
-
67
41
  extensions: []
68
-
69
- extra_rdoc_files:
70
- - LICENSE.txt
71
- - README.rdoc
72
- files:
42
+ extra_rdoc_files: []
43
+ files:
73
44
  - .document
45
+ - .gitignore
46
+ - .rspec
47
+ - .rvmrc
48
+ - .travis.yml
49
+ - CHANGELOG.md
74
50
  - Gemfile
75
- - Gemfile.lock
76
51
  - LICENSE.txt
77
- - README.rdoc
52
+ - README.md
78
53
  - Rakefile
79
- - VERSION
80
54
  - constant-redefinition.gemspec
81
55
  - lib/constant-redefinition.rb
82
- - test/helper.rb
83
- - test/test_constant-redefinition.rb
84
- has_rdoc: true
85
- homepage: http://github.com/czarneckid/constant-redefinition
86
- licenses:
87
- - MIT
56
+ - spec/constant-redefinition_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/czarneckid/constant-redefinition
59
+ licenses: []
88
60
  post_install_message:
89
61
  rdoc_options: []
90
-
91
- require_paths:
62
+ require_paths:
92
63
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
64
+ required_ruby_version: !ruby/object:Gem::Requirement
94
65
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 1728699172224103149
99
- segments:
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ segments:
100
71
  - 0
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
72
+ hash: -4258598608484863096
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
74
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
108
80
  - 0
109
- version: "0"
81
+ hash: -4258598608484863096
110
82
  requirements: []
111
-
112
- rubyforge_project:
113
- rubygems_version: 1.3.7
83
+ rubyforge_project: constant-redefinition
84
+ rubygems_version: 1.8.15
114
85
  signing_key:
115
86
  specification_version: 3
116
- summary: Allows you to define constants if not defined on an object and redefine constants without warning
117
- test_files:
118
- - test/helper.rb
119
- - test/test_constant-redefinition.rb
87
+ summary: Allows you to define constants if not defined on an object and redefine constants
88
+ without warning
89
+ test_files:
90
+ - spec/constant-redefinition_spec.rb
91
+ - spec/spec_helper.rb
@@ -1,18 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.5.1)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- rake (0.8.7)
10
- rcov (0.9.9)
11
-
12
- PLATFORMS
13
- ruby
14
-
15
- DEPENDENCIES
16
- bundler (~> 1.0.0)
17
- jeweler (~> 1.5.1)
18
- rcov
@@ -1,59 +0,0 @@
1
- = constant-redefinition
2
-
3
- Allows you to define constants if not defined on an object and redefine constants without warning.
4
-
5
- Define a constant if not defined:
6
-
7
- define_if_not_defined(:A, 1)
8
-
9
- assert_equal 1, A
10
-
11
- Define a constant and redefine it:
12
-
13
- define_if_not_defined(:B, 1)
14
- redefine_without_warning(:B, 2)
15
-
16
- assert_equal 2, B
17
-
18
- Redefine a constant which should set the constant:
19
-
20
- redefine_without_warning(:C, 3)
21
-
22
- assert_equal 3, C
23
-
24
- Define a constant within a module:
25
-
26
- Math.define_if_not_defined(:FOO, 2 * Math::PI)
27
-
28
- assert_equal 2 * Math::PI, Math::FOO
29
-
30
- Define and redefine a constant within a module:
31
-
32
- Math.define_if_not_defined(:BAR, 3)
33
- Math.redefine_without_warning(:BAR, 5)
34
-
35
- assert_equal 5, Math::BAR
36
-
37
- Redefine a constant within a module which should set the constant:
38
-
39
- Math.redefine_without_warning(:AMAZING, 3)
40
-
41
- assert_equal 3, Math::AMAZING
42
-
43
- All credit is due to this post: http://stackoverflow.com/questions/3375360/how-to-redefine-a-ruby-constant-without-warning
44
-
45
- == Contributing to constant-redefinition
46
-
47
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
48
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
49
- * Fork the project
50
- * Start a feature/bugfix branch
51
- * Commit and push until you are happy with your contribution
52
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
53
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
54
-
55
- == Copyright
56
-
57
- Copyright (c) 2010 David Czarnecki. See LICENSE.txt for
58
- further details.
59
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
-
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- require 'constant-redefinition'
15
-
16
- class Test::Unit::TestCase
17
- end
@@ -1,41 +0,0 @@
1
- require 'helper'
2
-
3
- class TestConstantRedefinition < Test::Unit::TestCase
4
- def test_can_define_a_constant_if_not_already_defined
5
- define_if_not_defined(:A, 1)
6
-
7
- assert_equal 1, A
8
- end
9
-
10
- def test_can_redefine_a_constant_if_already_defined
11
- define_if_not_defined(:B, 1)
12
- redefine_without_warning(:B, 2)
13
-
14
- assert_equal 2, B
15
- end
16
-
17
- def test_redefine_a_constant_sets_constant_if_not_already_defined
18
- redefine_without_warning(:C, 3)
19
-
20
- assert_equal 3, C
21
- end
22
-
23
- def test_can_define_a_constant_in_a_module_if_not_already_defined
24
- Math.define_if_not_defined(:FOO, 2 * Math::PI)
25
-
26
- assert_equal 2 * Math::PI, Math::FOO
27
- end
28
-
29
- def test_can_redefine_a_constant_in_a_module_if_already_defined
30
- Math.define_if_not_defined(:BAR, 3)
31
- Math.redefine_without_warning(:BAR, 5)
32
-
33
- assert_equal 5, Math::BAR
34
- end
35
-
36
- def test_redefine_a_constant_in_a_module_sets_constant_if_not_already_defined
37
- Math.redefine_without_warning(:AMAZING, 3)
38
-
39
- assert_equal 3, Math::AMAZING
40
- end
41
- end