rspec-match_ruby 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rspec/match_ruby.rb +53 -0
- data/lib/rspec/match_ruby/match_ruby.rb +33 -0
- data/lib/rspec/match_ruby/version.rb +5 -0
- data/rspec-match_ruby.gemspec +29 -0
- data/tes.rb +25 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e85da27fa05787a7511cfef0bdf0974bbd63a0c9
|
4
|
+
data.tar.gz: f4dc6f004185cd4f916d64e56836597754457051
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2003ad30b2b52fc6f7b5a9235195504534fb959327c69c21a5e7586a0e74038d9e87fb459f31f8442964cd8fef027d9f12b36098b6a1e673c1d9e5a6fb69d44
|
7
|
+
data.tar.gz: f40b310d5a57b69c2b1bfa4ea36e60fdd2a8eb1d9a11e2c4b805174130ff9cd847bff5c577adce8d109b2a6e16416a2f6b3454ababf32a22e3c19df45410e37c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-match_ruby (0.1.0)
|
5
|
+
parser
|
6
|
+
rspec (~> 3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.3.0)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
parser (2.4.0.2)
|
14
|
+
ast (~> 2.3)
|
15
|
+
rake (10.5.0)
|
16
|
+
rspec (3.7.0)
|
17
|
+
rspec-core (~> 3.7.0)
|
18
|
+
rspec-expectations (~> 3.7.0)
|
19
|
+
rspec-mocks (~> 3.7.0)
|
20
|
+
rspec-core (3.7.0)
|
21
|
+
rspec-support (~> 3.7.0)
|
22
|
+
rspec-expectations (3.7.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.7.0)
|
25
|
+
rspec-mocks (3.7.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.7.0)
|
28
|
+
rspec-support (3.7.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.16)
|
35
|
+
rake (~> 10.0)
|
36
|
+
rspec-match_ruby!
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.16.0
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# rspec-match_fuzzy
|
2
|
+
|
3
|
+
It is Ruby code matcher.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/winebarrel/rspec-match_ruby)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspec-match_ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-match_ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'rspec/match_ruby'
|
27
|
+
|
28
|
+
RSpec.describe do
|
29
|
+
specify do
|
30
|
+
code1 = <<-EOS
|
31
|
+
create_table :products, id: true, force: :cascade do |t|
|
32
|
+
t.string :name, null: false, limit: 4
|
33
|
+
t.text :description
|
34
|
+
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
EOS
|
38
|
+
|
39
|
+
code2 = <<-EOS
|
40
|
+
create_table :products, force: :cascade, id: true do |t|
|
41
|
+
t.string :name, limit: 4, null: true
|
42
|
+
t.text :description
|
43
|
+
# Comment
|
44
|
+
t.timestamps
|
45
|
+
end
|
46
|
+
EOS
|
47
|
+
|
48
|
+
expect(code1).to match_ruby code2
|
49
|
+
#=> Failure/Error: expect(code1).to match_ruby code2
|
50
|
+
# expected: "create_table :products, force: :cascade, id: true do |t|\nt.string :name, limit: 4, null: true\nt.text :description\n# Comment\nt.timestamps\nend"
|
51
|
+
# got: "create_table :products, id: true, force: :cascade do |t|\nt.string :name, null: false, limit: 4\nt.text :description\nt.timestamps\nend"
|
52
|
+
# Diff:
|
53
|
+
# @@ -1,7 +1,6 @@
|
54
|
+
# -create_table :products, force: :cascade, id: true do |t|
|
55
|
+
# -t.string :name, limit: 4, null: true
|
56
|
+
# +create_table :products, id: true, force: :cascade do |t|
|
57
|
+
# +t.string :name, null: false, limit: 4
|
58
|
+
# t.text :description
|
59
|
+
# -# Comment
|
60
|
+
# t.timestamps
|
61
|
+
# end
|
62
|
+
# @@ -14,7 +14,7 @@
|
63
|
+
# [:sym, :name],
|
64
|
+
# [:hash,
|
65
|
+
# [:pair, [:sym, :limit], [:int, 4]],
|
66
|
+
# - [:pair, [:sym, :null], [:true]]]],
|
67
|
+
# + [:pair, [:sym, :null], [:false]]]],
|
68
|
+
# [:send, [:lvar, :t], :text, [:sym, :description]],
|
69
|
+
# [:send, [:lvar, :t], :timestamps]]]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/match_ruby"
|
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/setup
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'parser/current'
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
require 'rspec/match_ruby/version'
|
5
|
+
require 'rspec/match_ruby/match_ruby'
|
6
|
+
|
7
|
+
RSpec::Matchers.define :match_ruby do |expected|
|
8
|
+
unless expected.is_a?(String)
|
9
|
+
raise TypeError, "wrong expected type #{expected.class} (expected String)"
|
10
|
+
end
|
11
|
+
|
12
|
+
match do |actual|
|
13
|
+
unless expected.is_a?(String)
|
14
|
+
raise TypeError, "wrong actual type #{expected.class} (expected String)"
|
15
|
+
end
|
16
|
+
|
17
|
+
Rspec::MatchRuby.match(expected, actual)
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message do |actual|
|
21
|
+
normalize = proc do |str|
|
22
|
+
str.strip.gsub(/^\s+/, '').gsub(/[[:blank:]]+/, "\s").gsub(/\n+/, "\n").gsub(/\s+$/, '')
|
23
|
+
end
|
24
|
+
|
25
|
+
actual_normalized = normalize.call(actual)
|
26
|
+
expected_normalized = normalize.call(expected)
|
27
|
+
|
28
|
+
actual_ast = Rspec::MatchRuby.parse(actual)
|
29
|
+
expected_ast = Rspec::MatchRuby.parse(expected)
|
30
|
+
|
31
|
+
message = <<-EOS.strip
|
32
|
+
expected: #{expected_normalized.inspect}
|
33
|
+
got: #{actual_normalized.inspect}
|
34
|
+
EOS
|
35
|
+
|
36
|
+
diff = RSpec::Expectations.differ.diff(actual_normalized, expected_normalized)
|
37
|
+
ast_diff = RSpec::Expectations.differ.diff(actual_ast.pretty_inspect, expected_ast.pretty_inspect)
|
38
|
+
|
39
|
+
if not diff.empty? or not ast_diff.empty?
|
40
|
+
message << "\n\n" << RSpec::Matchers::ExpectedsForMultipleDiffs::DEFAULT_DIFF_LABEL
|
41
|
+
end
|
42
|
+
|
43
|
+
unless diff.strip.empty?
|
44
|
+
message << diff
|
45
|
+
end
|
46
|
+
|
47
|
+
unless ast_diff.strip.empty?
|
48
|
+
message << ast_diff
|
49
|
+
end
|
50
|
+
|
51
|
+
message
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rspec
|
2
|
+
module MatchRuby
|
3
|
+
def parse(str)
|
4
|
+
node = Parser::CurrentRuby.parse(str)
|
5
|
+
expand_node(node)
|
6
|
+
end
|
7
|
+
module_function :parse
|
8
|
+
|
9
|
+
def match(expected, actual)
|
10
|
+
parse(expected) == parse(actual)
|
11
|
+
end
|
12
|
+
module_function :match
|
13
|
+
|
14
|
+
def expand_node(node)
|
15
|
+
children = node.children
|
16
|
+
|
17
|
+
if node.type == :hash
|
18
|
+
children = node.children.sort_by(&:to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
children = children.map do |child|
|
22
|
+
if child.is_a?(Parser::AST::Node)
|
23
|
+
expand_node(child)
|
24
|
+
else
|
25
|
+
child
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
[node.type, *children]
|
30
|
+
end
|
31
|
+
module_function :expand_node
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/match_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rspec-match_ruby'
|
8
|
+
spec.version = Rspec::MatchRuby::VERSION
|
9
|
+
spec.authors = ['winebarrel']
|
10
|
+
spec.email = ['sugawara@winebarrel.jp']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby code matcher.}
|
13
|
+
spec.description = %q{Ruby code matcher.}
|
14
|
+
spec.homepage = 'https://github.com/winebarrel/rspec-match_ruby'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
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_dependency 'rspec', '~> 3'
|
25
|
+
spec.add_dependency 'parser'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
end
|
data/tes.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rspec/match_ruby'
|
2
|
+
|
3
|
+
RSpec.describe do
|
4
|
+
specify do
|
5
|
+
code1 = <<-EOS
|
6
|
+
create_table :products, id: true, force: :cascade do |t|
|
7
|
+
t.string :name, null: false, limit: 4
|
8
|
+
t.text :description
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
|
14
|
+
code2 = <<-EOS
|
15
|
+
create_table :products, force: :cascade, id: true do |t|
|
16
|
+
t.string :name, limit: 4, null: true
|
17
|
+
t.text :description
|
18
|
+
# Comment
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
EOS
|
22
|
+
|
23
|
+
expect(code1).to match_ruby code2
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-match_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- winebarrel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parser
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Ruby code matcher.
|
70
|
+
email:
|
71
|
+
- sugawara@winebarrel.jp
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/rspec/match_ruby.rb
|
86
|
+
- lib/rspec/match_ruby/match_ruby.rb
|
87
|
+
- lib/rspec/match_ruby/version.rb
|
88
|
+
- rspec-match_ruby.gemspec
|
89
|
+
- tes.rb
|
90
|
+
homepage: https://github.com/winebarrel/rspec-match_ruby
|
91
|
+
licenses: []
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.6.13
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Ruby code matcher.
|
113
|
+
test_files: []
|