proc_matcher 0.1.0

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: 91c2c37f15a8168450b50718dc9e856521f7b69e
4
+ data.tar.gz: 56956d019ea8803825c4f1c6dda17774c83cabb7
5
+ SHA512:
6
+ metadata.gz: 46d39f19156fe63c30a325c33244f2ec45fbdc8204447e00f1a973e7f019524e681b328e5b5dd4c644f10e3c760232aa1935f562e8416ea4adc42d5e685c7967
7
+ data.tar.gz: 50eaf646ec1f9393900c5eb75ec21665c62c80f4d9e6bbe19fcbb657d1279240399db079e79b13d568195ca421e98c955cd1855c48ce55e1e37d722ecf7bba87
data/.codeclimate.yml ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ engines:
3
+ fixme:
4
+ enabled: true
5
+ rubocop:
6
+ enabled: true
7
+ ratings:
8
+ paths:
9
+ - "**.rb"
10
+ exclude_paths:
11
+ - spec/**/*
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /Gemfile.lock
2
+ /coverage/
3
+ /pkg/
4
+ /tmp/
5
+ .idea/
6
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - 'tmp/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ before_install: gem install bundler -v 1.10.6
@@ -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 proc_matcher.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,4 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^lib/(.+)\.rb$}) { 'spec' }
3
+ watch(%r{^spec/(.+)\.rb$}) { 'spec' }
4
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Declan Whelan
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,94 @@
1
+ [![Gem Version](https://badge.fury.io/rb/proc_matcher.png)](http://badge.fury.io/rb/proc_matcher)
2
+ [![Build Status](https://travis-ci.org/dwhelan/proc_matcher.png?branch=master)](https://travis-ci.org/dwhelan/proc_matcher)
3
+ [![Code Climate](https://codeclimate.com/github/dwhelan/proc_matcher/badges/gpa.svg)](https://codeclimate.com/github/dwhelan/proc_matcher)
4
+ [![Coverage Status](https://coveralls.io/repos/dwhelan/proc_matcher/badge.svg?branch=master&service=github)](https://coveralls.io/github/dwhelan/proc_matcher?branch=master)
5
+
6
+ # ProcMatcher
7
+
8
+ A matcher for testing proc and lambda equivalance.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'proc_matcher'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install proc_matcher
25
+
26
+ ## Usage
27
+
28
+ Add this line to your `spec_helper.rb` file:
29
+
30
+ ```ruby
31
+ include 'proc_matcher'
32
+ ```
33
+
34
+ You will now have access to a matcher called `has_same_source_as` which
35
+ allows you to check that `procs's` have the source code.
36
+
37
+ ```ruby
38
+ require 'spec_helper'
39
+
40
+ describe 'have_same_source_as' do
41
+ let(:proc1) do
42
+ proc {}
43
+ end
44
+
45
+ it 'the same procs should be equal' do
46
+ expect(proc1).to have_same_source_as proc1
47
+ end
48
+
49
+ it 'lambdas should not have the same source as procs' do
50
+ expect(proc1).to_not have_same_source_as -> {}
51
+ end
52
+
53
+ it 'procs with different parameters only should by default not have the same source' do
54
+ proc1 = proc { |a| a.to_s }
55
+
56
+ expect(proc1).to_not have_same_source_as proc { |b| b.to_s }
57
+ end
58
+ end
59
+ ```
60
+
61
+ The `ignoring_parameter_names` allows blocks to be considered to have the same
62
+ source if they only differ in their parameter names:
63
+
64
+ ```ruby
65
+ require 'spec_helper'
66
+
67
+ describe 'ignoring_parameter_names' do
68
+ it 'ignoring_parameter_names should allow procs with same effective source but different parameters to have the same source' do
69
+ proc1 = proc { |a| a.to_s }
70
+
71
+ expect(proc1).to have_same_source_as(proc { |b| b.to_s }).ignoring_parameter_names
72
+ end
73
+ end
74
+ ```
75
+
76
+ *Note* this matcher depends the `sourcify` gem to extact the source code.
77
+ This source extraction only works if:
78
+ * the proc is the only proc declared on the same line
79
+ * the proc was not created via an `eval`
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dwhelan/proc_matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
90
+
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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 do |task|
7
+ task.options << '--display-cop-names'
8
+ end
9
+
10
+ task default: [:spec, :rubocop, :build]
@@ -0,0 +1,5 @@
1
+ require 'rspec/matchers'
2
+ require 'proc_extensions'
3
+
4
+ require 'proc_matcher/version'
5
+ require 'proc_matcher/have_same_source_as'
@@ -0,0 +1,31 @@
1
+ module RSpec
2
+ module Matchers
3
+ define(:have_same_source_as) do
4
+ chain(:ignoring_parameter_names) { self.ignore_parameter_names = true }
5
+
6
+ match do
7
+ if ignore_parameter_names
8
+ source_for(actual).match source_for(expected)
9
+ else
10
+ source_for(actual) == source_for(expected)
11
+ end
12
+ end
13
+
14
+ description do
15
+ "have same source as #{description_of(expected)}#{ignore_parameter_names ? ' ignoring parameter names' : ''}"
16
+ end
17
+
18
+ def description_of(object)
19
+ super(source_for(object).inspect)
20
+ end
21
+
22
+ private
23
+
24
+ attr_accessor :ignore_parameter_names
25
+
26
+ def source_for(proc)
27
+ ProcSource.new(proc)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module ProcMatcher
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'proc_matcher/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = 'proc_matcher'
9
+ gem.version = ProcMatcher::VERSION
10
+ gem.authors = ['Declan Whelan']
11
+ gem.email = ['dwhelan@leanintuit.com']
12
+
13
+ gem.summary = 'A matcher for testing proc and lambda equivalance.'
14
+ gem.description = 'A matcher for testing proc and lambda equivalance.'
15
+ gem.homepage = 'https://github.com/dwhelan/proc_matcher'
16
+ gem.license = 'MIT'
17
+
18
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
19
+ gem.test_files = gem.files.grep(%r{^spec/})
20
+ gem.require_paths = ['lib']
21
+
22
+ gem.add_runtime_dependency 'proc_extensions', '~> 0.1'
23
+
24
+ gem.add_development_dependency 'bundler', '~> 1.10'
25
+ gem.add_development_dependency 'coveralls', '~> 0.7'
26
+ gem.add_development_dependency 'guard', '~> 2.13'
27
+ gem.add_development_dependency 'guard-rspec', '~> 4.6'
28
+
29
+ if RUBY_VERSION =~ /2/
30
+ gem.add_development_dependency 'pry-byebug', '~> 3.3'
31
+ else
32
+ gem.add_development_dependency 'pry-debugger', '~> 0.2'
33
+ end
34
+
35
+ gem.add_development_dependency 'rake', '~> 10.0'
36
+ gem.add_development_dependency 'rspec', '~> 3.0'
37
+ gem.add_development_dependency 'rspec-its', '~> 1.1'
38
+ gem.add_development_dependency 'rubocop', '~> 0.30'
39
+ gem.add_development_dependency 'simplecov', '~> 0.9'
40
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proc_matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Declan Whelan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: proc_extensions
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-its
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.30'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.30'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.9'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.9'
167
+ description: A matcher for testing proc and lambda equivalance.
168
+ email:
169
+ - dwhelan@leanintuit.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".codeclimate.yml"
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".rubocop.yml"
178
+ - ".travis.yml"
179
+ - CODE_OF_CONDUCT.md
180
+ - Gemfile
181
+ - Guardfile
182
+ - LICENSE.txt
183
+ - README.md
184
+ - Rakefile
185
+ - lib/proc_matcher.rb
186
+ - lib/proc_matcher/have_same_source_as.rb
187
+ - lib/proc_matcher/version.rb
188
+ - proc_matcher.gemspec
189
+ homepage: https://github.com/dwhelan/proc_matcher
190
+ licenses:
191
+ - MIT
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubyforge_project:
209
+ rubygems_version: 2.4.6
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: A matcher for testing proc and lambda equivalance.
213
+ test_files: []