rspec-match_ruby 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/rspec/match_ruby.rb +4 -5
- data/lib/rspec/rspec_match_ruby.rb +31 -0
- data/rspec-match_ruby.gemspec +1 -2
- metadata +2 -3
- data/lib/rspec/match_ruby/match_ruby.rb +0 -33
- data/lib/rspec/match_ruby/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71175c4228078fa1f94552e4acac39a34ef4e9a
|
4
|
+
data.tar.gz: 4ca968408159dc319c0f4ce0a07407e6d4cd0256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4f7e2ed72e373cdaf34a3c8130a5057ca6d7a6156788fddafb003e49ffb3ded6fefe1705bea15224409672864ecf11ae8568f73339a7f6f63f12e8bcaa99cf8
|
7
|
+
data.tar.gz: f517058073453b483053f61a50825678bb37d221e4393ab4cff4f035ce35267b88fe8e92f34925e38557b87539d5c43b4637f9dc0aa25388d8624ceb80c24086
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
It is Ruby code matcher.
|
4
4
|
|
5
|
+
[](https://badge.fury.io/rb/rspec-match_ruby)
|
5
6
|
[](https://travis-ci.org/winebarrel/rspec-match_ruby)
|
6
7
|
|
7
8
|
## Installation
|
data/lib/rspec/match_ruby.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'parser/current'
|
2
2
|
require 'rspec'
|
3
3
|
|
4
|
-
require 'rspec/
|
5
|
-
require 'rspec/match_ruby/match_ruby'
|
4
|
+
require 'rspec/rspec_match_ruby'
|
6
5
|
|
7
6
|
RSpec::Matchers.define :match_ruby do |expected|
|
8
7
|
unless expected.is_a?(String)
|
@@ -14,7 +13,7 @@ RSpec::Matchers.define :match_ruby do |expected|
|
|
14
13
|
raise TypeError, "wrong actual type #{expected.class} (expected String)"
|
15
14
|
end
|
16
15
|
|
17
|
-
|
16
|
+
RSpecMatchRuby.match(expected, actual)
|
18
17
|
end
|
19
18
|
|
20
19
|
failure_message do |actual|
|
@@ -25,8 +24,8 @@ RSpec::Matchers.define :match_ruby do |expected|
|
|
25
24
|
actual_normalized = normalize.call(actual)
|
26
25
|
expected_normalized = normalize.call(expected)
|
27
26
|
|
28
|
-
actual_ast =
|
29
|
-
expected_ast =
|
27
|
+
actual_ast = RSpecMatchRuby.parse(actual)
|
28
|
+
expected_ast = RSpecMatchRuby.parse(expected)
|
30
29
|
|
31
30
|
message = <<-EOS.strip
|
32
31
|
expected: #{expected_normalized.inspect}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RSpecMatchRuby
|
2
|
+
def parse(str)
|
3
|
+
node = Parser::CurrentRuby.parse(str)
|
4
|
+
expand_node(node)
|
5
|
+
end
|
6
|
+
module_function :parse
|
7
|
+
|
8
|
+
def match(expected, actual)
|
9
|
+
parse(expected) == parse(actual)
|
10
|
+
end
|
11
|
+
module_function :match
|
12
|
+
|
13
|
+
def expand_node(node)
|
14
|
+
children = node.children
|
15
|
+
|
16
|
+
if node.type == :hash
|
17
|
+
children = node.children.sort_by(&:to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
children = children.map do |child|
|
21
|
+
if child.is_a?(Parser::AST::Node)
|
22
|
+
expand_node(child)
|
23
|
+
else
|
24
|
+
child
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
[node.type, *children]
|
29
|
+
end
|
30
|
+
module_function :expand_node
|
31
|
+
end
|
data/rspec-match_ruby.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'rspec/match_ruby/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = 'rspec-match_ruby'
|
8
|
-
spec.version =
|
7
|
+
spec.version = '0.1.1'
|
9
8
|
spec.authors = ['winebarrel']
|
10
9
|
spec.email = ['sugawara@winebarrel.jp']
|
11
10
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-match_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -83,8 +83,7 @@ files:
|
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
85
|
- lib/rspec/match_ruby.rb
|
86
|
-
- lib/rspec/
|
87
|
-
- lib/rspec/match_ruby/version.rb
|
86
|
+
- lib/rspec/rspec_match_ruby.rb
|
88
87
|
- rspec-match_ruby.gemspec
|
89
88
|
- tes.rb
|
90
89
|
homepage: https://github.com/winebarrel/rspec-match_ruby
|
@@ -1,33 +0,0 @@
|
|
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
|