rspec-act-like 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/lib/act_like/matcher.rb +50 -0
- data/lib/act_like/rspec.rb +40 -0
- data/lib/act_like/version.rb +3 -0
- data/lib/rspec-act-like.rb +1 -0
- data/rspec-act-like.gemspec +28 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f8a5dc425a5809727911cd0da01d4e25d2b6e46
|
4
|
+
data.tar.gz: 4116fdc36720549cb24fcb7ff6fec7bdd5aa96e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37b3a095444025108f341b62e43151b01f7bb54aa9eff0e02ec42d89eb209b0a75869595dd83fd786a27d5bcef10c24fa9b09c9ddea4f0dddeaf8e7d6da1e426
|
7
|
+
data.tar.gz: 5fb6baa4ca83495769e8fe2df5771847972ec21d9350e970cf9d0ef2b8d9d48607de00f01d55e17ab8d392477514c7065b9869f4300dae342afffc647a957626
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec-act-like"
|
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(__FILE__)
|
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module ActLike
|
2
|
+
class Matcher
|
3
|
+
attr_reader :offenses
|
4
|
+
|
5
|
+
def initialize(actual, expected)
|
6
|
+
@actual = actual
|
7
|
+
@expected = expected
|
8
|
+
@offenses = Hash.new { |offenses, offense| offenses[offense] = Array.new }
|
9
|
+
end
|
10
|
+
|
11
|
+
def check
|
12
|
+
check_class_methods
|
13
|
+
check_instance_methods
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :actual, :expected
|
19
|
+
|
20
|
+
def check_instance_methods
|
21
|
+
expected
|
22
|
+
.public_instance_methods
|
23
|
+
.map(&expected.method(:public_instance_method))
|
24
|
+
.each_with_object(offenses) { |method, offenses|
|
25
|
+
begin
|
26
|
+
unless actual.public_instance_method(method.name).arity == method.arity
|
27
|
+
offenses[:arity] << method.name.to_s
|
28
|
+
end
|
29
|
+
rescue NameError
|
30
|
+
offenses[:missing] << method.name.to_s
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def check_class_methods
|
36
|
+
expected
|
37
|
+
.public_methods
|
38
|
+
.map(&expected.method(:public_method))
|
39
|
+
.each_with_object(offenses) { |method, offenses|
|
40
|
+
begin
|
41
|
+
unless actual.public_method(method.name).arity == method.arity
|
42
|
+
offenses[:arity] << "self.#{method.name}"
|
43
|
+
end
|
44
|
+
rescue NameError
|
45
|
+
offenses[:missing] << "self.#{method.name}"
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'act_like/matcher'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :act_like do |expected|
|
4
|
+
match do |actual|
|
5
|
+
matcher = ActLike::Matcher.new(actual, expected)
|
6
|
+
matcher.check
|
7
|
+
@offenses = matcher.offenses
|
8
|
+
@offenses.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |actual|
|
12
|
+
<<-MSG
|
13
|
+
expected #{actual.inspect} to act like #{expected.inspect}
|
14
|
+
|
15
|
+
#{missing_methods}
|
16
|
+
#{bad_arity}
|
17
|
+
MSG
|
18
|
+
# TODO arity details, kwargs details
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message_when_negated do |actual|
|
22
|
+
"expected #{actual.inspect} not to act like #{expected.inspect}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def missing_methods
|
28
|
+
offenses = @offenses[:missing]
|
29
|
+
unless offenses.empty?
|
30
|
+
"Missing methods: #{offenses.join(', ')}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def bad_arity
|
35
|
+
offenses = @offenses[:arity]
|
36
|
+
unless offenses.empty?
|
37
|
+
"Bad arity: #{offenses.join(', ')}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'act_like/rspec'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "act_like/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rspec-act-like'
|
8
|
+
spec.version = ActsLike::VERSION
|
9
|
+
spec.authors = ['Jay Hayes']
|
10
|
+
spec.email = ['ur@iamvery.com']
|
11
|
+
|
12
|
+
spec.summary = %q{An RSpec matcher that tests one type acts like another.}
|
13
|
+
spec.description = %q{An RSpec matcher that tests one type acts like another.}
|
14
|
+
spec.homepage = 'https://github.com/iamvery/rspec-act-like'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-act-like
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jay Hayes
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: An RSpec matcher that tests one type acts like another.
|
70
|
+
email:
|
71
|
+
- ur@iamvery.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/rake
|
83
|
+
- bin/rspec
|
84
|
+
- bin/setup
|
85
|
+
- lib/act_like/matcher.rb
|
86
|
+
- lib/act_like/rspec.rb
|
87
|
+
- lib/act_like/version.rb
|
88
|
+
- lib/rspec-act-like.rb
|
89
|
+
- rspec-act-like.gemspec
|
90
|
+
homepage: https://github.com/iamvery/rspec-act-like
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.13
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: An RSpec matcher that tests one type acts like another.
|
114
|
+
test_files: []
|