method_match 0.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +5 -0
- data/data/test_data/matcher.rb +14 -0
- data/lib/method_match/matcher.rb +60 -0
- data/lib/method_match/pry.rb +15 -0
- data/lib/method_match/version.rb +3 -0
- data/lib/method_match.rb +7 -0
- data/method_match.gemspec +22 -0
- data/spec/method_match/matcher_spec.rb +40 -0
- data/spec/spec_helper.rb +15 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tomasz Tokarski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# MethodMatch [](http://travis-ci.org/tiokksar/method_match)
|
2
|
+
|
3
|
+
Tiny gem for runnig specs for given file and line
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'method_match'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install method_match
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module MethodMatch
|
2
|
+
class Matcher
|
3
|
+
require 'pry'
|
4
|
+
attr_accessor :name, :line, :spec_name
|
5
|
+
SPEC_MODE = 'spec'
|
6
|
+
CODE_MODE = 'code'
|
7
|
+
|
8
|
+
def initialize name, line
|
9
|
+
@name = name
|
10
|
+
@line = line
|
11
|
+
create_spec_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def mode
|
15
|
+
is_spec unless @mode
|
16
|
+
@mode
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_name
|
20
|
+
return nil if mode == SPEC_MODE
|
21
|
+
@match = get_method_match
|
22
|
+
return nil unless @match
|
23
|
+
@match.match(/def (self\.(\w+)|\w+).*/)[1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def rspec_command
|
27
|
+
command = "rspec #{spec_name}"
|
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
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_spec
|
38
|
+
if @spec_name[0] == SPEC_MODE
|
39
|
+
@mode = SPEC_MODE
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
@mode = CODE_MODE
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_spec_name
|
47
|
+
@spec_name = @name.split('/')
|
48
|
+
if is_spec
|
49
|
+
return @spec_name = @name
|
50
|
+
end
|
51
|
+
@spec_name[0] = SPEC_MODE
|
52
|
+
@spec_name[-1].sub!('.rb', '_spec.rb')
|
53
|
+
@spec_name = @spec_name.join('/')
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_method_match
|
57
|
+
File.readlines(name).first(line).reverse.grep(/ def/).first
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MethodMatch
|
2
|
+
class Pry
|
3
|
+
def self.setup
|
4
|
+
require 'pry'
|
5
|
+
::Pry::CommandSet.new do
|
6
|
+
create_command "rspec_method", "runs " do
|
7
|
+
group "Testing"
|
8
|
+
def process(*args)
|
9
|
+
MethodMatch::Matcher.new(args[0], Integer(args[1])).run_command
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end.tap { |cmd| ::Pry::Commands.import cmd }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/method_match.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'method_match/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "method_match"
|
8
|
+
gem.version = MethodMatch::VERSION
|
9
|
+
gem.authors = ["Tomasz Tokarski"]
|
10
|
+
gem.email = ["tomasz@tomasztokarski.com"]
|
11
|
+
gem.description = %q{Method name matcher and test runner for given file and line}
|
12
|
+
gem.summary = %q{Method name matcher and test runner for given file and line}
|
13
|
+
gem.homepage = "https://github.com/tiokksar/scrapzirra"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency 'pry'
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
describe MethodMatch::Matcher do
|
3
|
+
let(:matcher){MethodMatch::Matcher.new 'data/test_data/matcher.rb', 11}
|
4
|
+
subject {matcher}
|
5
|
+
its(:name){ should eq('data/test_data/matcher.rb')}
|
6
|
+
|
7
|
+
describe '#spec_name' do
|
8
|
+
subject { matcher.spec_name }
|
9
|
+
context 'sample_data' do
|
10
|
+
it { should eq('spec/test_data/matcher_spec.rb')}
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'rails model' do
|
14
|
+
let(:matcher){MethodMatch::Matcher.new 'app/models/model.rb', 11}
|
15
|
+
it { should eq('spec/models/model_spec.rb')}
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'spec' do
|
19
|
+
let(:matcher){MethodMatch::Matcher.new 'spec/some_spec.rb', 11}
|
20
|
+
it { should eq('spec/some_spec.rb')}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#method_name' do
|
25
|
+
subject { matcher.method_name }
|
26
|
+
context 'spec' do
|
27
|
+
let(:matcher){MethodMatch::Matcher.new 'spec/some_spec.rb', 11}
|
28
|
+
it { should be_nil}
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'test class' do
|
32
|
+
it { should eq('parse_file')}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#rspec_command' do
|
37
|
+
subject { matcher.rspec_command }
|
38
|
+
it { should eq('rspec spec/test_data/matcher_spec.rb -e \'#parse_file\'')}
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter "/spec/"
|
5
|
+
end
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/method_match')
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_match
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomasz Tokarski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
name: pry
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
type: :development
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
name: rspec
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
type: :development
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
name: rake
|
62
|
+
description: Method name matcher and test runner for given file and line
|
63
|
+
email:
|
64
|
+
- tomasz@tomasztokarski.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- data/test_data/matcher.rb
|
75
|
+
- lib/method_match.rb
|
76
|
+
- lib/method_match/matcher.rb
|
77
|
+
- lib/method_match/pry.rb
|
78
|
+
- lib/method_match/version.rb
|
79
|
+
- method_match.gemspec
|
80
|
+
- spec/method_match/matcher_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: https://github.com/tiokksar/scrapzirra
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Method name matcher and test runner for given file and line
|
106
|
+
test_files:
|
107
|
+
- spec/method_match/matcher_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
has_rdoc:
|