shoulda_runner 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -17
- data/lib/shoulda_runner/ast_builder.rb +42 -18
- data/lib/shoulda_runner/parser.rb +52 -0
- data/lib/shoulda_runner/version.rb +1 -1
- data/lib/shoulda_runner.rb +1 -47
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a238eb33e8bbd09efb385afec8c9316ce4cddbf
|
4
|
+
data.tar.gz: 44e83cd242f17fd8826701ee964cbbc7af8da0fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d24161a3d5bbbf2b9b6082f3dd7fbb5592947d71ae2515d411e77600b48c910270302b23bfa66ee00ec16e2130340c5eae355751f449aa37e74919bce77281df
|
7
|
+
data.tar.gz: edabe3365584a35c6a14ec297b2c6d14182af24a31bce458385a8a97bdf001a939cbce5703b203f155fe61ec66d6764ef0750433b37769df2fb5938bb67ced41
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# ShouldaRunner
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem makes it possible to run single test cases when using the `shoulda` gem.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem '
|
10
|
+
gem 'shoulda_runner'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -18,19 +16,10 @@ And then execute:
|
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
$ gem install
|
19
|
+
$ gem install shoulda_runner
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
23
|
+
```
|
25
24
|
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shoulda_vim.
|
36
|
-
|
25
|
+
```
|
@@ -2,57 +2,81 @@ require 'tree'
|
|
2
2
|
|
3
3
|
module ShouldaRunner
|
4
4
|
class AstBuilder
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :asts
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@source =
|
7
|
+
def initialize(source_code)
|
8
|
+
@source = source_code
|
9
|
+
@asts = []
|
9
10
|
end
|
10
11
|
|
11
12
|
def parse
|
12
13
|
stack = []
|
13
14
|
each_source_code_line do |line, number|
|
14
|
-
if line =~ /^class\s
|
15
|
+
if line =~ /^class\s(\S+);\send$/
|
16
|
+
# Do nothing
|
17
|
+
elsif line =~ /^class\s/
|
15
18
|
stack = []
|
16
|
-
|
17
|
-
|
18
|
-
elsif line =~ /^context\s/
|
19
|
+
stack.push class_node(line)
|
20
|
+
elsif line =~ /^context\s.+do$/
|
19
21
|
stack.push context_node(line)
|
20
|
-
elsif line =~ /^should\s
|
22
|
+
elsif line =~ /^should\s.+do$/
|
21
23
|
stack.push should_node(line, number)
|
24
|
+
elsif line =~ /^def\s/
|
25
|
+
stack.push disposable_node(line)
|
22
26
|
elsif line =~ /(do|do\s\|.+\|$)/
|
23
27
|
stack.push disposable_node(line)
|
24
28
|
elsif line =~ /^end$/
|
25
29
|
node = stack.pop
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
parent
|
30
|
+
unless node.nil?
|
31
|
+
node.content[:line_range][:to] = number if node.content[:line_range]
|
32
|
+
parent = stack.pop
|
33
|
+
if parent
|
34
|
+
parent << node unless node.content[:dispose]
|
35
|
+
stack.push parent
|
36
|
+
else
|
37
|
+
@asts << node
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
unless stack.empty?
|
44
|
+
while !stack.empty?
|
45
|
+
node = stack.pop
|
46
|
+
unless stack.empty?
|
47
|
+
parent = stack.pop
|
48
|
+
parent << node
|
30
49
|
stack.push parent
|
31
|
-
else
|
32
|
-
@ast = node
|
33
50
|
end
|
34
51
|
end
|
52
|
+
|
53
|
+
@asts << node
|
35
54
|
end
|
36
55
|
end
|
37
56
|
|
38
57
|
private
|
39
58
|
|
40
59
|
def class_node(line)
|
41
|
-
|
42
|
-
|
60
|
+
# TODO: This regex may need some love
|
61
|
+
matches = line.match(/^class\s((?<class_name>[^\s<;]+)(\s<\s(?<base_class_name>[^\s;]+))?|<<\s(?<self_name>\S+))/)
|
62
|
+
if !matches[:self_name].nil?
|
63
|
+
class_name = "#{matches[:self_name]}#test_: "
|
64
|
+
else
|
65
|
+
class_name = "#{matches[:class_name]}#test_: "
|
66
|
+
end
|
43
67
|
|
44
68
|
Tree::TreeNode.new(class_name, { name: class_name, source_line: line })
|
45
69
|
end
|
46
70
|
|
47
71
|
def context_node(line)
|
48
|
-
matches = line.match(/^context\s('|")(?<context_text
|
72
|
+
matches = line.match(/^context\s('|")(?<context_text>.+)('|")\sdo$/)
|
49
73
|
context_text = "#{matches[:context_text]} "
|
50
74
|
|
51
75
|
Tree::TreeNode.new(context_text, { name: context_text, source_line: line })
|
52
76
|
end
|
53
77
|
|
54
78
|
def should_node(line, line_number)
|
55
|
-
matches = line.match(/^should\s('|")(?<should_text
|
79
|
+
matches = line.match(/^should\s('|")(?<should_text>.+)('|")\sdo$/)
|
56
80
|
should_text = "should #{matches[:should_text]}. "
|
57
81
|
|
58
82
|
Tree::TreeNode.new(should_text, { name: should_text, source_line: line, line_range: { from: line_number } })
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'shoulda_runner/ast_builder'
|
2
|
+
|
3
|
+
module ShouldaRunner
|
4
|
+
class Parser
|
5
|
+
def initialize(test_file_path)
|
6
|
+
@source = File.read(test_file_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def select_test(linenumber)
|
10
|
+
test_names[linenumber]
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def test_names
|
16
|
+
@asts ||= build_asts
|
17
|
+
hash = {}
|
18
|
+
@asts.each do |ast|
|
19
|
+
ast.each do |node|
|
20
|
+
if node.children.empty?
|
21
|
+
from = node.content[:line_range][:from]
|
22
|
+
to = node.content[:line_range][:to]
|
23
|
+
test_name = build_test_name(node)
|
24
|
+
|
25
|
+
from.upto(to) do |line|
|
26
|
+
hash[line] = test_name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
hash
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_test_name(node)
|
36
|
+
test_name_string = node.content[:name]
|
37
|
+
parent = node.parent
|
38
|
+
while parent != nil
|
39
|
+
test_name_string = "#{parent.content[:name]}#{test_name_string}"
|
40
|
+
parent = parent.parent
|
41
|
+
end
|
42
|
+
|
43
|
+
test_name_string
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_asts
|
47
|
+
ast_builder = AstBuilder.new(@source)
|
48
|
+
ast_builder.parse
|
49
|
+
@asts = ast_builder.asts
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/shoulda_runner.rb
CHANGED
@@ -1,51 +1,5 @@
|
|
1
1
|
require 'shoulda_runner/version'
|
2
|
-
require 'shoulda_runner/
|
2
|
+
require 'shoulda_runner/parser'
|
3
3
|
|
4
4
|
module ShouldaRunner
|
5
|
-
class Parser
|
6
|
-
def initialize(test_file_path)
|
7
|
-
@path = test_file_path
|
8
|
-
end
|
9
|
-
|
10
|
-
def select_test(linenumber)
|
11
|
-
test_names[linenumber]
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def test_names
|
17
|
-
@ast ||= build_ast
|
18
|
-
hash = {}
|
19
|
-
@ast.each do |node|
|
20
|
-
if node.children.empty?
|
21
|
-
from = node.content[:line_range][:from]
|
22
|
-
to = node.content[:line_range][:to]
|
23
|
-
test_name = build_test_name(node)
|
24
|
-
|
25
|
-
from.upto(to) do |line|
|
26
|
-
hash[line] = test_name
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
hash
|
32
|
-
end
|
33
|
-
|
34
|
-
def build_test_name(node)
|
35
|
-
test_name_string = node.content[:name]
|
36
|
-
parent = node.parent
|
37
|
-
while parent != nil
|
38
|
-
test_name_string = "#{parent.content[:name]}#{test_name_string}"
|
39
|
-
parent = parent.parent
|
40
|
-
end
|
41
|
-
|
42
|
-
test_name_string
|
43
|
-
end
|
44
|
-
|
45
|
-
def build_ast
|
46
|
-
ast_builder = AstBuilder.new(@path)
|
47
|
-
ast_builder.parse
|
48
|
-
@ast = ast_builder.ast
|
49
|
-
end
|
50
|
-
end
|
51
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda_runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giuseppe Modarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubytree
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- Rakefile
|
99
99
|
- lib/shoulda_runner.rb
|
100
100
|
- lib/shoulda_runner/ast_builder.rb
|
101
|
+
- lib/shoulda_runner/parser.rb
|
101
102
|
- lib/shoulda_runner/version.rb
|
102
103
|
- shoulda_runner.gemspec
|
103
104
|
homepage: ''
|