method_match 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/method_match.rb +3 -2
- data/lib/method_match/command_runner.rb +24 -0
- data/lib/method_match/matcher.rb +3 -11
- data/lib/method_match/pry.rb +3 -1
- data/lib/method_match/version.rb +1 -1
- metadata +2 -1
data/lib/method_match.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "method_match/version"
|
2
2
|
|
3
3
|
module MethodMatch
|
4
|
-
autoload :Matcher,
|
5
|
-
autoload :Pry,
|
4
|
+
autoload :Matcher, 'method_match/matcher'
|
5
|
+
autoload :Pry, 'method_match/pry'
|
6
|
+
autoload :CommandRunner, 'method_match/command_runner'
|
6
7
|
Pry.setup
|
7
8
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MethodMatch
|
2
|
+
class CommandRunner
|
3
|
+
require 'pry'
|
4
|
+
def initialize matcher
|
5
|
+
@matcher = matcher
|
6
|
+
end
|
7
|
+
|
8
|
+
def run_command
|
9
|
+
require 'pathname'
|
10
|
+
if Pathname.new(@matcher.spec_name).file?
|
11
|
+
::Pry.run_command rspec_command
|
12
|
+
else
|
13
|
+
puts "Spec #{@matcher.spec_name} does not exist"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def rspec_command
|
18
|
+
command = "rspec #{@matcher.spec_name}"
|
19
|
+
command += " -e '##{@matcher.method_name}'" if @matcher.method_name
|
20
|
+
command += ":#{line}" if @matcher.spec?
|
21
|
+
command
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/method_match/matcher.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module MethodMatch
|
2
2
|
class Matcher
|
3
|
-
require 'pry'
|
4
3
|
attr_accessor :name, :line, :spec_name
|
5
4
|
SPEC_MODE = 'spec'
|
6
5
|
CODE_MODE = 'code'
|
@@ -23,15 +22,8 @@ module MethodMatch
|
|
23
22
|
@match.match(/def (self\.(\w+)|\w+).*/)[1]
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
27
|
-
|
28
|
-
command += " -e '##{method_name}'" if method_name
|
29
|
-
command += ":#{line}" if mode == SPEC_MODE
|
30
|
-
command
|
31
|
-
end
|
32
|
-
|
33
|
-
def run_command
|
34
|
-
::Pry.run_command rspec_command
|
25
|
+
def spec?
|
26
|
+
mode == SPEC_MODE
|
35
27
|
end
|
36
28
|
|
37
29
|
def is_spec
|
@@ -55,7 +47,7 @@ module MethodMatch
|
|
55
47
|
|
56
48
|
def get_method_match
|
57
49
|
File.readlines(name).first(line).reverse.grep(/ def/).first
|
58
|
-
rescue
|
50
|
+
rescue LoadError
|
59
51
|
return nil
|
60
52
|
end
|
61
53
|
end
|
data/lib/method_match/pry.rb
CHANGED
@@ -6,7 +6,9 @@ module MethodMatch
|
|
6
6
|
create_command "rspec_method", "runs " do
|
7
7
|
group "Testing"
|
8
8
|
def process(*args)
|
9
|
-
|
9
|
+
CommandRunner.new(
|
10
|
+
Matcher.new(args[0], Integer(args[1]))
|
11
|
+
).run_command
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end.tap { |cmd| ::Pry::Commands.import cmd }
|
data/lib/method_match/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: method_match
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tomasz Tokarski
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- Rakefile
|
74
74
|
- data/test_data/matcher.rb
|
75
75
|
- lib/method_match.rb
|
76
|
+
- lib/method_match/command_runner.rb
|
76
77
|
- lib/method_match/matcher.rb
|
77
78
|
- lib/method_match/pry.rb
|
78
79
|
- lib/method_match/version.rb
|