shoulda_runner 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85cb97c8c9697b94f7963507b22fb4123ac9fda3
4
- data.tar.gz: 9b6c9b84b4617ad84dee53104853df87fd0e0e9a
3
+ metadata.gz: 4a238eb33e8bbd09efb385afec8c9316ce4cddbf
4
+ data.tar.gz: 44e83cd242f17fd8826701ee964cbbc7af8da0fb
5
5
  SHA512:
6
- metadata.gz: e50ca46a01cb3f9659a61e90225ce8e6e20aef61c604be9db13d8b556507451b6b88efe2d9d0d55177f505a2d3b5fbc38865977ae27fda26bac2b98a1f9a12cb
7
- data.tar.gz: 3e7df1ade8cb67de0b6d611cfd050310b59289d02bac55fc2290dca474656cf2b09e2232f2893ded4759426653cab7c2e4cb752bbc4c83864e6bcd3049bac58a
6
+ metadata.gz: d24161a3d5bbbf2b9b6082f3dd7fbb5592947d71ae2515d411e77600b48c910270302b23bfa66ee00ec16e2130340c5eae355751f449aa37e74919bce77281df
7
+ data.tar.gz: edabe3365584a35c6a14ec297b2c6d14182af24a31bce458385a8a97bdf001a939cbce5703b203f155fe61ec66d6764ef0750433b37769df2fb5938bb67ced41
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
- # ShouldaVim
1
+ # ShouldaRunner
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shoulda_vim`. To experiment with that code, run `bin/console` for an interactive prompt.
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 'shoulda_vim'
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 shoulda_vim
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 :ast
5
+ attr_reader :asts
6
6
 
7
- def initialize(path)
8
- @source = File.read(path)
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
- node = class_node(line)
17
- stack.push node
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
- node.content[:line_range][:to] = number if node.content[:line_range]
27
- parent = stack.pop
28
- if parent
29
- parent << node unless node.content[:dispose]
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
- matches = line.match(/^class\s(?<class_name>\w+)\s<\s.+$/)
42
- class_name = "#{matches[:class_name]}#test_: "
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>[\w\s]+)('|")\sdo$/)
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>[\w\s]+)('|")\sdo$/)
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
@@ -1,3 +1,3 @@
1
1
  module ShouldaRunner
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,51 +1,5 @@
1
1
  require 'shoulda_runner/version'
2
- require 'shoulda_runner/ast_builder'
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.0
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-03 00:00:00.000000000 Z
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: ''