stub_constant 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bb11cd6614dc06ed87f026767ab34d4961a2488
4
+ data.tar.gz: faf076110985f42780937efae4a503ba3b1793c3
5
+ SHA512:
6
+ metadata.gz: 0273caf953aedd37b972c0657e79a9daab979794dd8db9a9ddc2c3928573ee222884ca0b4cd86cc190b12bf0f0a2c526f6905e4491b5ace92a75e4805c7a9886
7
+ data.tar.gz: abc2f0b4135a3f877781848f02aa2c6757f03ebf18f868e2292c09b699250b64b3fc77e49740c9c32865ecd3914049e8ab4aaa1f7d8e708913a43c75dd6f4f0b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "bin/*"
4
+
5
+ Style/StringLiterals:
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/SignalException:
9
+ EnforcedStyle: only_raise
10
+
11
+ Style/HashSyntax:
12
+ EnforcedStyle: hash_rockets
13
+
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+
17
+ Style/Documentation:
18
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
6
+ - 2.2.2
7
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stub_constant.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Max Jacobson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # StubConstant
2
+
3
+ Here's a gem I'm extracting from my friend Máximo's gem [Journeyman][journeyman]
4
+ mostly to understand better how it works and also because I'd like to use it in
5
+ my gems.
6
+
7
+ [journeyman]: https://github.com/ElMassimo/journeyman
8
+
9
+ When practicing TDD, you may want to test your code in extreme isolation. The
10
+ idea is that any given test is only exercising the object "under test", and any
11
+ other code should not be included unless it's strictly necessary to do so. The
12
+ other code should also be tested, separately, in isolation.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile (probably in the test section):
17
+
18
+ ```ruby
19
+ gem 'stub_constant'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install stub_constant
29
+
30
+ ## Usage
31
+
32
+ Note: this is "optimstic" because I haven't implemented it yet. But I think it
33
+ will look like this:
34
+
35
+ ```ruby
36
+ Cloneable # error
37
+ StubConstant.module(:Cloneable)
38
+ Cloneable # no error
39
+ Cloneable.class #=> Module
40
+ ```
41
+
42
+ ```ruby
43
+ Dog # error
44
+ StubConstant.klass(:Dog)
45
+ Dog # no error
46
+ Dog.class #=> Class
47
+ ```
48
+
49
+ ```ruby
50
+ LIMIT # error
51
+ StubConstant.value(:LIMIT, 4)
52
+ LIMIT # no error
53
+ LIMIT.class #=> Fixnum
54
+ ```
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
59
+ `bin/rake` to run the tests. You can also run `bin/console` for an interactive
60
+ prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bin/rake install`. To
63
+ release a new version, update the version number in `version.rb`, and then run
64
+ `bin/rake release`, which will create a git tag for the version, push
65
+ git commits and tags, and push the `.gem` file to
66
+ [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at
71
+ https://github.com/maxjacobson/stub_constant. This project is intended to be a
72
+ safe, welcoming space for collaboration, and contributors are expected to
73
+ adhere to the [Contributor Covenant](http://contributor-covenant.org) code of
74
+ conduct.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT
79
+ License](http://opensource.org/licenses/MIT).
80
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
7
+
8
+ task :default => [:spec, :rubocop]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stub_constant"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ class StubConstant
2
+ VERSION = "1.0.0.beta"
3
+ end
@@ -0,0 +1,48 @@
1
+ require "stub_constant/version"
2
+
3
+ class StubConstant
4
+ def self.module(full_name)
5
+ new(full_name).stub_with { Module.new }
6
+ end
7
+
8
+ def self.klass(full_name)
9
+ new(full_name).stub_with { Class.new }
10
+ end
11
+
12
+ def self.value(full_name, value)
13
+ new(full_name).stub_with { value }
14
+ end
15
+
16
+ def initialize(full_name)
17
+ @full_name = full_name
18
+ end
19
+
20
+ def stub_with(&block)
21
+ full_name.to_s.split(/::/).inject(Object) do |context, name|
22
+ begin
23
+ context.const_get(name)
24
+ rescue NameError
25
+ # Defer substitution of a stub module/class to the last possible
26
+ # moment by overloading const_missing. We use a module here so
27
+ # we can "stack" const_missing definitions for various
28
+ # constants.
29
+ mod = Module.new do
30
+ define_method(:const_missing) do |missing_const_name|
31
+ if missing_const_name.to_s == name.to_s
32
+ value = block.call
33
+ const_set(name, value)
34
+ value
35
+ else
36
+ super(missing_const_name)
37
+ end
38
+ end
39
+ end
40
+ context.extend(mod)
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :full_name
48
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "stub_constant/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stub_constant"
8
+ spec.version = StubConstant::VERSION
9
+ spec.authors = ["Máximo Mussini", "Max Jacobson"]
10
+ spec.email = ["maximomussini@gmail.com", "max@hardscrabble.net"]
11
+
12
+ spec.summary = "Super easy way to stub classes and modules for tests"
13
+ spec.description = "While writing isolation tests, you may want to " \
14
+ "stub constants. This makes it super easy."
15
+ spec.homepage = "https://github.com/maxjacobson/stub_constant"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rubocop", "~> 0.32"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "rspec"
30
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stub_constant
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Máximo Mussini
8
+ - Max Jacobson
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubocop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.32'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.32'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: While writing isolation tests, you may want to stub constants. This makes
85
+ it super easy.
86
+ email:
87
+ - maximomussini@gmail.com
88
+ - max@hardscrabble.net
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
96
+ - ".travis.yml"
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/rake
104
+ - bin/rspec
105
+ - bin/rubocop
106
+ - bin/setup
107
+ - lib/stub_constant.rb
108
+ - lib/stub_constant/version.rb
109
+ - stub_constant.gemspec
110
+ homepage: https://github.com/maxjacobson/stub_constant
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">"
126
+ - !ruby/object:Gem::Version
127
+ version: 1.3.1
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.5
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Super easy way to stub classes and modules for tests
134
+ test_files: []