rubocop-yast 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +14 -9
- data/Rakefile +3 -24
- data/config/default.yml +4 -0
- data/lib/rubocop-yast.rb +1 -0
- data/lib/rubocop/cop/yast/log_variable.rb +23 -0
- data/lib/rubocop/cop/yast/ops.rb +1 -1
- data/lib/rubocop/yast/builtins/y2log.rb +1 -0
- data/lib/rubocop/yast/version.rb +1 -1
- data/rubocop-yast.gemspec +1 -1
- data/spec/builtins_spec.rb +13 -20
- data/spec/ops_spec.rb +0 -2
- data/spec/spec_helper.rb +0 -18
- metadata +12 -16
- data/spec/builtins_spec.md +0 -614
- data/spec/rspec_code.rb +0 -47
- data/spec/rspec_renderer.rb +0 -206
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c59e960c99f00013d3881020fe1d576e9d67ab91
|
4
|
+
data.tar.gz: 89d463fb18eb4d31ad00df25be33621cd4309446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6f08655ccfef688328df7f9f245df9c963ed4a55c963ae81b40395e71befa4fca00f50c8fba339f80223689863a24d51c49ff41e923d166880555d2efb02087
|
7
|
+
data.tar.gz: ea903ebf6261f79f6a7e7b3646648d198ae0432b3da2e301dbc2b29a1d07e23a7c8b9ddcf849f4d3c46b221b6d0ff11ef97879952bedbde3c66e8bc4d2fb834e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
## 0.0.6 (15/12/2014)
|
6
|
+
|
7
|
+
### New Features
|
8
|
+
|
9
|
+
- added `LogVariable` Cop (check for `log` variable assignment)
|
10
|
+
|
11
|
+
### Changes
|
12
|
+
|
13
|
+
- converted MarkDown test descriptions to Cucumber (removed our specific
|
14
|
+
Markdown -> RSpec renderer)
|
15
|
+
|
16
|
+
### Fixed Bugs
|
17
|
+
|
18
|
+
- `Ops` Cop - fixed crash when using `--auto-gen-config` option
|
19
|
+
- `Builtins` Cop - fixed crash when parenthesis were missing aroung method argument
|
data/README.md
CHANGED
@@ -2,11 +2,11 @@ rubocop-yast
|
|
2
2
|
============
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/rubocop-yast.svg)](http://badge.fury.io/rb/rubocop-yast)
|
5
|
-
[![Dependency Status](https://gemnasium.com/
|
6
|
-
[![Travis Build](https://travis-ci.org/
|
7
|
-
[![Coverage Status](https://img.shields.io/coveralls/
|
8
|
-
[![Code Climate](https://codeclimate.com/github/
|
9
|
-
[![Inline docs](http://inch-ci.org/github/
|
5
|
+
[![Dependency Status](https://gemnasium.com/yast/rubocop-yast.svg)](https://gemnasium.com/yast/rubocop-yast)
|
6
|
+
[![Travis Build](https://travis-ci.org/yast/rubocop-yast.svg?branch=master)](https://travis-ci.org/yast/rubocop-yast)
|
7
|
+
[![Coverage Status](https://img.shields.io/coveralls/yast/rubocop-yast.svg)](https://coveralls.io/r/yast/rubocop-yast?branch=master)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/yast/rubocop-yast/badges/gpa.svg)](https://codeclimate.com/github/yast/rubocop-yast)
|
9
|
+
[![Inline docs](http://inch-ci.org/github/yast/rubocop-yast.svg?branch=master)](http://inch-ci.org/github/yast/rubocop-yast)
|
10
10
|
|
11
11
|
|
12
12
|
This is a plugin for [RuboCop](https://github.com/bbatsov/rubocop)
|
@@ -18,8 +18,8 @@ The goal is to create a Rubocop plugin which can check for
|
|
18
18
|
covert some ugly code parts introduced by the automatic code conversion done by
|
19
19
|
[YCP Killer](https://github.com/yast/ycp-killer) (conversion from YCP to Ruby).
|
20
20
|
|
21
|
-
Check [the
|
22
|
-
detection and code conversion.
|
21
|
+
Check [the RSpec tests](spec) and [the Cucumber features](features)to see
|
22
|
+
the examples of offense detection and code conversion.
|
23
23
|
|
24
24
|
*The plugin is currently in early development, always manually check the chages
|
25
25
|
done by the plugin! It can eat your code... ;-)*
|
@@ -35,6 +35,9 @@ you can install it using the `gem` command:
|
|
35
35
|
sudo gem install rubocop-yast
|
36
36
|
```
|
37
37
|
|
38
|
+
You can also install the latest development version directly from the Git repository,
|
39
|
+
see [Building a Gem](#building-a-gem) section below.
|
40
|
+
|
38
41
|
Usage
|
39
42
|
-----
|
40
43
|
|
@@ -73,8 +76,9 @@ Development
|
|
73
76
|
|
74
77
|
### Prerequisites
|
75
78
|
|
76
|
-
For development you need some extra development gems. The best way is to install them with [Bundler](http://bundler.io/). To avoid a possible collision with system gems
|
77
|
-
|
79
|
+
For development you need some extra development gems. The best way is to install them with [Bundler](http://bundler.io/). To avoid a possible collision with system gems (esp. RSpec,
|
80
|
+
Yast still uses version 2.14 while rubocop-yast uses 3.1) it is recommended
|
81
|
+
to install the gems into a local subdirectory using:
|
78
82
|
|
79
83
|
```shell
|
80
84
|
bundle install --path vendor/bundle
|
@@ -131,3 +135,4 @@ and then run:
|
|
131
135
|
bundle exec rake release
|
132
136
|
```
|
133
137
|
|
138
|
+
(Note: You need push permissions at [rubygems.org](https://rubygems.org/gems/rubocop-yast).)
|
data/Rakefile
CHANGED
@@ -10,34 +10,13 @@ rescue Bundler::BundlerError => e
|
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
12
|
|
13
|
-
require "
|
14
|
-
|
15
|
-
|
16
|
-
def render_markdown(renderer_class, task)
|
17
|
-
puts "Rendering file: #{task.name}"
|
18
|
-
markdown = Redcarpet::Markdown.new(renderer_class, fenced_code_blocks: true)
|
19
|
-
|
20
|
-
string = markdown.render(File.read(task.prerequisites[0]))
|
21
|
-
File.write(task.name, string)
|
22
|
-
end
|
23
|
-
|
24
|
-
renderer = "spec/rspec_renderer.rb"
|
25
|
-
|
26
|
-
file "spec/builtins_spec.rb" => ["spec/builtins_spec.md", renderer] do |t|
|
27
|
-
render_markdown(RSpecRenderer, t)
|
28
|
-
end
|
29
|
-
|
30
|
-
file "spec/builtins_spec.html" => ["spec/builtins_spec.md", renderer] do |t|
|
31
|
-
render_markdown(Redcarpet::Render::HTML, t)
|
32
|
-
end
|
33
|
-
desc "Render the specification to HTML locally"
|
34
|
-
task html: ["spec/builtins_spec.html"]
|
13
|
+
require "cucumber/rake/task"
|
14
|
+
Cucumber::Rake::Task.new(:features)
|
35
15
|
|
36
16
|
require "rspec/core/rake_task"
|
37
17
|
RSpec::Core::RakeTask.new(:spec)
|
38
|
-
task spec: ["spec/builtins_spec.rb"]
|
39
18
|
|
40
19
|
require "rubocop/rake_task"
|
41
20
|
RuboCop::RakeTask.new(:rubocop)
|
42
21
|
|
43
|
-
task default: [:spec, :rubocop]
|
22
|
+
task default: [:spec, :features, :rubocop]
|
data/config/default.yml
CHANGED
data/lib/rubocop-yast.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rubocop/cop/cop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Yast
|
8
|
+
# This cop checks for using log variable
|
9
|
+
# code like:
|
10
|
+
# log = "msg"
|
11
|
+
# can override the included logger
|
12
|
+
class LogVariable < Cop
|
13
|
+
MSG = "Do not use `log` variable, it can conflict with the logger."
|
14
|
+
|
15
|
+
def on_lvasgn(node)
|
16
|
+
name, _value = *node
|
17
|
+
|
18
|
+
add_offense(node, :name, MSG) if name == :log
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/rubocop/cop/yast/ops.rb
CHANGED
@@ -88,6 +88,7 @@ module RuboCop
|
|
88
88
|
# Add Yast::Logger include somewhere up in the tree
|
89
89
|
def add_missing_logger(node, corrector)
|
90
90
|
target_node = parent_node_type(node, [:class, :module])
|
91
|
+
target_node = target_node.children.first if target_node.begin_type?
|
91
92
|
|
92
93
|
# already added or already present
|
93
94
|
return if added_includes.include?(target_node) ||
|
data/lib/rubocop/yast/version.rb
CHANGED
data/rubocop-yast.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_runtime_dependency("rubocop", "~> 0.27")
|
32
32
|
|
33
33
|
spec.add_development_dependency("rake")
|
34
|
-
spec.add_development_dependency("redcarpet", "~> 3")
|
35
34
|
spec.add_development_dependency("rspec", "~> 3.1.0")
|
35
|
+
spec.add_development_dependency("cucumber")
|
36
36
|
spec.add_development_dependency("simplecov")
|
37
37
|
end
|
data/spec/builtins_spec.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe "RuboCop
|
5
|
+
describe "RuboCop::Cop::Yast::Builtins" do
|
6
6
|
describe "Generic Tests:" do
|
7
7
|
it "It reports y2milestone builtin as offense" do
|
8
8
|
code = code_cleanup(<<-EOT)
|
@@ -13,7 +13,6 @@ describe "RuboCop-Yast" do
|
|
13
13
|
inspect_source(cop, [code])
|
14
14
|
|
15
15
|
expect(cop.offenses.size).to eq(1)
|
16
|
-
expect(cop.messages.first).to match(/Builtin call `.*` is obsolete/)
|
17
16
|
end
|
18
17
|
|
19
18
|
it "It finds builtin in explicit Yast namespace" do
|
@@ -25,7 +24,6 @@ describe "RuboCop-Yast" do
|
|
25
24
|
inspect_source(cop, [code])
|
26
25
|
|
27
26
|
expect(cop.offenses.size).to eq(1)
|
28
|
-
expect(cop.messages.first).to match(/Builtin call `.*` is obsolete/)
|
29
27
|
end
|
30
28
|
|
31
29
|
it "It finds builtin in explicit ::Yast namespace" do
|
@@ -37,7 +35,6 @@ describe "RuboCop-Yast" do
|
|
37
35
|
inspect_source(cop, [code])
|
38
36
|
|
39
37
|
expect(cop.offenses.size).to eq(1)
|
40
|
-
expect(cop.messages.first).to match(/Builtin call `.*` is obsolete/)
|
41
38
|
end
|
42
39
|
|
43
40
|
it "Builtins in the ::Builtins name space are ignored" do
|
@@ -89,21 +86,6 @@ describe "RuboCop-Yast" do
|
|
89
86
|
end
|
90
87
|
end
|
91
88
|
|
92
|
-
describe "Builtins.time():" do
|
93
|
-
it "Is trivially converted to `::Time.now.to_i`" do
|
94
|
-
original_code = code_cleanup(<<-EOT)
|
95
|
-
Builtins.time()
|
96
|
-
EOT
|
97
|
-
|
98
|
-
translated_code = code_cleanup(<<-EOT)
|
99
|
-
::Time.now.to_i
|
100
|
-
EOT
|
101
|
-
|
102
|
-
cop = RuboCop::Cop::Yast::Builtins.new
|
103
|
-
expect(autocorrect_source(cop, original_code)).to eq(translated_code)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
89
|
describe "Builtins.getenv():" do
|
108
90
|
it "With string literal parameter is translated to ENV equivalent" do
|
109
91
|
original_code = code_cleanup(<<-EOT)
|
@@ -147,7 +129,7 @@ describe "RuboCop-Yast" do
|
|
147
129
|
end
|
148
130
|
end
|
149
131
|
|
150
|
-
describe "Logging
|
132
|
+
describe "Logging - Builtins.y2debug(), ...:" do
|
151
133
|
it "It translates `y2debug` to `log.debug`" do
|
152
134
|
original_code = code_cleanup(<<-EOT)
|
153
135
|
Builtins.y2debug("foo")
|
@@ -563,5 +545,16 @@ describe "RuboCop-Yast" do
|
|
563
545
|
cop = RuboCop::Cop::Yast::Builtins.new
|
564
546
|
expect(autocorrect_source(cop, original_code)).to eq(translated_code)
|
565
547
|
end
|
548
|
+
|
549
|
+
it "It finds an offense with missing parenthesis around argument" do
|
550
|
+
code = code_cleanup(<<-EOT)
|
551
|
+
Builtins.y2milestone "Executing hook '\#{name}'"
|
552
|
+
EOT
|
553
|
+
|
554
|
+
cop = RuboCop::Cop::Yast::Builtins.new
|
555
|
+
inspect_source(cop, [code])
|
556
|
+
|
557
|
+
expect(cop.offenses.size).to eq(1)
|
558
|
+
end
|
566
559
|
end
|
567
560
|
end
|
data/spec/ops_spec.rb
CHANGED
@@ -95,7 +95,6 @@ describe RuboCop::Cop::Yast::Ops do
|
|
95
95
|
new_source = autocorrect_source(cop, source)
|
96
96
|
expect(new_source).to eq(source)
|
97
97
|
end
|
98
|
-
|
99
98
|
end
|
100
99
|
|
101
100
|
context("In unsafe mode") do
|
@@ -117,5 +116,4 @@ describe RuboCop::Cop::Yast::Ops do
|
|
117
116
|
expect(new_source).to eq("foo + bar")
|
118
117
|
end
|
119
118
|
end
|
120
|
-
|
121
119
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,18 +2,6 @@
|
|
2
2
|
|
3
3
|
require "simplecov"
|
4
4
|
|
5
|
-
# use coveralls for on-line code coverage reporting at Travis CI
|
6
|
-
if ENV["TRAVIS"]
|
7
|
-
require "coveralls"
|
8
|
-
|
9
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
|
-
SimpleCov::Formatter::HTMLFormatter,
|
11
|
-
Coveralls::SimpleCov::Formatter
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
|
-
SimpleCov.minimum_coverage 95
|
16
|
-
|
17
5
|
SimpleCov.start do
|
18
6
|
# don't check code coverage in these subdirectories
|
19
7
|
add_filter "/vendor/"
|
@@ -38,10 +26,4 @@ require File.join(
|
|
38
26
|
|
39
27
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
40
28
|
|
41
|
-
def code_cleanup(s)
|
42
|
-
s.split("\n").reject { |l| l =~ /^\s*$/ }.first =~ /^(\s*)/
|
43
|
-
return s.dup if Regexp.last_match.nil?
|
44
|
-
s.gsub(Regexp.new("^#{Regexp.last_match[1]}"), "")[0..-2]
|
45
|
-
end
|
46
|
-
|
47
29
|
require "rubocop-yast"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-yast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ladislav Slezák
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -39,33 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.1.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: cucumber
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +91,7 @@ extra_rdoc_files:
|
|
91
91
|
- LICENSE
|
92
92
|
- README.md
|
93
93
|
files:
|
94
|
+
- CHANGELOG.md
|
94
95
|
- Gemfile
|
95
96
|
- LICENSE
|
96
97
|
- README.md
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- config/default.yml
|
99
100
|
- lib/rubocop-yast.rb
|
100
101
|
- lib/rubocop/cop/yast/builtins.rb
|
102
|
+
- lib/rubocop/cop/yast/log_variable.rb
|
101
103
|
- lib/rubocop/cop/yast/ops.rb
|
102
104
|
- lib/rubocop/yast/builtins/builtin.rb
|
103
105
|
- lib/rubocop/yast/builtins/getenv.rb
|
@@ -111,11 +113,8 @@ files:
|
|
111
113
|
- lib/rubocop/yast/variable_scope.rb
|
112
114
|
- lib/rubocop/yast/version.rb
|
113
115
|
- rubocop-yast.gemspec
|
114
|
-
- spec/builtins_spec.md
|
115
116
|
- spec/builtins_spec.rb
|
116
117
|
- spec/ops_spec.rb
|
117
|
-
- spec/rspec_code.rb
|
118
|
-
- spec/rspec_renderer.rb
|
119
118
|
- spec/spec_helper.rb
|
120
119
|
homepage: http://github.com/yast/rubocop-yast
|
121
120
|
licenses:
|
@@ -142,9 +141,6 @@ signing_key:
|
|
142
141
|
specification_version: 4
|
143
142
|
summary: Specific YaST Rubocop checks
|
144
143
|
test_files:
|
145
|
-
- spec/builtins_spec.md
|
146
144
|
- spec/builtins_spec.rb
|
147
145
|
- spec/ops_spec.rb
|
148
|
-
- spec/rspec_code.rb
|
149
|
-
- spec/rspec_renderer.rb
|
150
146
|
- spec/spec_helper.rb
|
data/spec/builtins_spec.md
DELETED
@@ -1,614 +0,0 @@
|
|
1
|
-
Builtins Cop
|
2
|
-
============
|
3
|
-
|
4
|
-
Table Of Contents
|
5
|
-
-----------------
|
6
|
-
|
7
|
-
1. Description
|
8
|
-
1. Builtins.time()
|
9
|
-
1. Builtins.getenv()
|
10
|
-
1. Logging
|
11
|
-
|
12
|
-
Description
|
13
|
-
-----------
|
14
|
-
|
15
|
-
This Cop is designed to check for `Builtins` call presence. These calls were
|
16
|
-
added by YCP Killer to ensure 100% compatibily of the translated Ruby code
|
17
|
-
with the old YCP.
|
18
|
-
|
19
|
-
But these calls should not be used in the new code, native Ruby methods should
|
20
|
-
be used instead of these wrappers.
|
21
|
-
|
22
|
-
The Cop can autocorrect some trivial or easy translatable builtins.
|
23
|
-
|
24
|
-
Generic Tests
|
25
|
-
-------------
|
26
|
-
|
27
|
-
It reports y2milestone builtin as offense
|
28
|
-
|
29
|
-
**Offense**
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
Builtins.y2milestone("foo")
|
33
|
-
```
|
34
|
-
|
35
|
-
It finds builtin in explicit Yast namespace
|
36
|
-
|
37
|
-
**Offense**
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
Yast::Builtins.y2milestone("foo")
|
41
|
-
```
|
42
|
-
|
43
|
-
It finds builtin in explicit ::Yast namespace
|
44
|
-
|
45
|
-
**Offense**
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
::Yast::Builtins.y2milestone("foo")
|
49
|
-
```
|
50
|
-
|
51
|
-
Builtins in the ::Builtins name space are ignored
|
52
|
-
|
53
|
-
**Accepted**
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
::Builtins.y2milestone("foo")
|
57
|
-
```
|
58
|
-
|
59
|
-
Builtins in non Yast name space are ignored
|
60
|
-
|
61
|
-
**Accepted**
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
Foo::Builtins.y2milestone("foo")
|
65
|
-
```
|
66
|
-
|
67
|
-
lsort(), crypt and gettext builtins are allowed
|
68
|
-
|
69
|
-
**Accepted**
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
Builtins.lsort(["foo"])
|
73
|
-
Builtins.crypt("foo")
|
74
|
-
Builtins.dgettext("domain", "foo")
|
75
|
-
```
|
76
|
-
|
77
|
-
It does not change unknown builtins
|
78
|
-
|
79
|
-
**Unchanged**
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
Builtins.foo()
|
83
|
-
```
|
84
|
-
|
85
|
-
|
86
|
-
Builtins.time()
|
87
|
-
---------------
|
88
|
-
|
89
|
-
Is trivially converted to `::Time.now.to_i`
|
90
|
-
|
91
|
-
**Original**
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
Builtins.time()
|
95
|
-
```
|
96
|
-
|
97
|
-
**Translated**
|
98
|
-
|
99
|
-
```ruby
|
100
|
-
::Time.now.to_i
|
101
|
-
```
|
102
|
-
|
103
|
-
Builtins.getenv()
|
104
|
-
-----------------
|
105
|
-
|
106
|
-
With string literal parameter is translated to ENV equivalent
|
107
|
-
|
108
|
-
**Original**
|
109
|
-
|
110
|
-
```ruby
|
111
|
-
Builtins.getenv("foo")
|
112
|
-
```
|
113
|
-
|
114
|
-
**Translated**
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
ENV["foo"]
|
118
|
-
```
|
119
|
-
|
120
|
-
Variable as parameter is preserved.
|
121
|
-
|
122
|
-
**Original**
|
123
|
-
|
124
|
-
```ruby
|
125
|
-
foo = bar
|
126
|
-
Builtins.getenv(foo)
|
127
|
-
```
|
128
|
-
|
129
|
-
**Translated**
|
130
|
-
|
131
|
-
```ruby
|
132
|
-
foo = bar
|
133
|
-
ENV[foo]
|
134
|
-
```
|
135
|
-
|
136
|
-
Any other statement is preserved.
|
137
|
-
|
138
|
-
**Original**
|
139
|
-
|
140
|
-
```ruby
|
141
|
-
Builtins.getenv(Ops.add(foo, bar))
|
142
|
-
```
|
143
|
-
|
144
|
-
**Translated**
|
145
|
-
|
146
|
-
```ruby
|
147
|
-
ENV[Ops.add(foo, bar)]
|
148
|
-
```
|
149
|
-
|
150
|
-
Logging
|
151
|
-
--------
|
152
|
-
|
153
|
-
It translates `y2debug` to `log.debug`
|
154
|
-
|
155
|
-
**Original**
|
156
|
-
|
157
|
-
```ruby
|
158
|
-
Builtins.y2debug("foo")
|
159
|
-
```
|
160
|
-
|
161
|
-
**Translated**
|
162
|
-
|
163
|
-
```ruby
|
164
|
-
include Yast::Logger
|
165
|
-
log.debug "foo"
|
166
|
-
```
|
167
|
-
|
168
|
-
It translates `y2milestone` to `log.info`
|
169
|
-
|
170
|
-
**Original**
|
171
|
-
|
172
|
-
```ruby
|
173
|
-
Builtins.y2milestone("foo")
|
174
|
-
```
|
175
|
-
|
176
|
-
**Translated**
|
177
|
-
|
178
|
-
```ruby
|
179
|
-
include Yast::Logger
|
180
|
-
log.info "foo"
|
181
|
-
```
|
182
|
-
|
183
|
-
It translates `y2warning` to `log.warn`
|
184
|
-
|
185
|
-
**Original**
|
186
|
-
|
187
|
-
```ruby
|
188
|
-
Builtins.y2warning("foo")
|
189
|
-
```
|
190
|
-
|
191
|
-
**Translated**
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
include Yast::Logger
|
195
|
-
log.warn "foo"
|
196
|
-
```
|
197
|
-
|
198
|
-
It translates `y2error` to `log.error`
|
199
|
-
|
200
|
-
**Original**
|
201
|
-
|
202
|
-
```ruby
|
203
|
-
Builtins.y2error("foo")
|
204
|
-
```
|
205
|
-
|
206
|
-
**Translated**
|
207
|
-
|
208
|
-
```ruby
|
209
|
-
include Yast::Logger
|
210
|
-
log.error "foo"
|
211
|
-
```
|
212
|
-
|
213
|
-
It translates `y2security` to `log.error`
|
214
|
-
|
215
|
-
**Original**
|
216
|
-
|
217
|
-
```ruby
|
218
|
-
Builtins.y2security("foo")
|
219
|
-
```
|
220
|
-
|
221
|
-
**Translated**
|
222
|
-
|
223
|
-
```ruby
|
224
|
-
include Yast::Logger
|
225
|
-
log.error "foo"
|
226
|
-
```
|
227
|
-
|
228
|
-
It translates `y2internal` to `log.fatal`
|
229
|
-
|
230
|
-
**Original**
|
231
|
-
|
232
|
-
```ruby
|
233
|
-
Builtins.y2internal("foo")
|
234
|
-
```
|
235
|
-
|
236
|
-
**Translated**
|
237
|
-
|
238
|
-
```ruby
|
239
|
-
include Yast::Logger
|
240
|
-
log.fatal "foo"
|
241
|
-
```
|
242
|
-
|
243
|
-
It adds the include statement only once
|
244
|
-
|
245
|
-
**Original**
|
246
|
-
|
247
|
-
```ruby
|
248
|
-
Builtins.y2milestone("foo")
|
249
|
-
Builtins.y2milestone("foo")
|
250
|
-
```
|
251
|
-
|
252
|
-
**Translated**
|
253
|
-
|
254
|
-
```ruby
|
255
|
-
include Yast::Logger
|
256
|
-
log.info \"foo\"
|
257
|
-
log.info \"foo\"
|
258
|
-
```
|
259
|
-
|
260
|
-
It converts YCP sformat to Ruby interpolation
|
261
|
-
|
262
|
-
**Original**
|
263
|
-
|
264
|
-
```ruby
|
265
|
-
Builtins.y2milestone("foo: %1", foo)
|
266
|
-
```
|
267
|
-
|
268
|
-
**Translated**
|
269
|
-
|
270
|
-
```ruby
|
271
|
-
include Yast::Logger
|
272
|
-
log.info "foo: #{foo}"
|
273
|
-
```
|
274
|
-
|
275
|
-
It converts %% in the format string to simple %.
|
276
|
-
|
277
|
-
**Original**
|
278
|
-
|
279
|
-
```ruby
|
280
|
-
Builtins.y2milestone("foo: %1%%", foo)
|
281
|
-
```
|
282
|
-
|
283
|
-
**Translated**
|
284
|
-
|
285
|
-
```ruby
|
286
|
-
include Yast::Logger
|
287
|
-
log.info "foo: #{foo}%"
|
288
|
-
```
|
289
|
-
|
290
|
-
It replaces repeated % placeholders in the format string
|
291
|
-
|
292
|
-
**Original**
|
293
|
-
|
294
|
-
```ruby
|
295
|
-
Builtins.y2warning("%1 %1", foo)
|
296
|
-
```
|
297
|
-
|
298
|
-
**Translated**
|
299
|
-
|
300
|
-
```ruby
|
301
|
-
include Yast::Logger
|
302
|
-
log.warn "#{foo} #{foo}"
|
303
|
-
```
|
304
|
-
|
305
|
-
The % placeholders do not need to start from 1
|
306
|
-
|
307
|
-
**Original**
|
308
|
-
|
309
|
-
```ruby
|
310
|
-
Builtins.y2warning("%2 %2", foo, bar)
|
311
|
-
```
|
312
|
-
|
313
|
-
**Translated**
|
314
|
-
|
315
|
-
```ruby
|
316
|
-
include Yast::Logger
|
317
|
-
log.warn "#{bar} #{bar}"
|
318
|
-
```
|
319
|
-
|
320
|
-
The % placeholders do not need to be in ascending order
|
321
|
-
|
322
|
-
**Original**
|
323
|
-
|
324
|
-
```ruby
|
325
|
-
Builtins.y2warning("%2 %1", foo, bar)
|
326
|
-
```
|
327
|
-
|
328
|
-
**Translated**
|
329
|
-
|
330
|
-
```ruby
|
331
|
-
include Yast::Logger
|
332
|
-
log.warn "#{bar} #{foo}"
|
333
|
-
```
|
334
|
-
|
335
|
-
It keeps the original statements in interpolated string
|
336
|
-
|
337
|
-
**Original**
|
338
|
-
|
339
|
-
```ruby
|
340
|
-
Builtins.y2warning("%1", foo + bar)
|
341
|
-
```
|
342
|
-
|
343
|
-
**Translated**
|
344
|
-
|
345
|
-
```ruby
|
346
|
-
include Yast::Logger
|
347
|
-
log.warn "#{foo + bar}"
|
348
|
-
```
|
349
|
-
|
350
|
-
It converts a log with string interpolation
|
351
|
-
|
352
|
-
**Original**
|
353
|
-
|
354
|
-
```ruby
|
355
|
-
Builtins.y2warning("foo: #{foo}")
|
356
|
-
```
|
357
|
-
|
358
|
-
**Translated**
|
359
|
-
|
360
|
-
```ruby
|
361
|
-
include Yast::Logger
|
362
|
-
log.warn "foo: #{foo}"
|
363
|
-
```
|
364
|
-
|
365
|
-
It converts a log with a message variable
|
366
|
-
|
367
|
-
**Original**
|
368
|
-
|
369
|
-
```ruby
|
370
|
-
msg = "message"
|
371
|
-
Builtins.y2warning(msg)
|
372
|
-
```
|
373
|
-
|
374
|
-
**Translated**
|
375
|
-
|
376
|
-
```ruby
|
377
|
-
include Yast::Logger
|
378
|
-
msg = "message"
|
379
|
-
log.warn msg
|
380
|
-
```
|
381
|
-
|
382
|
-
It converts a log with function call
|
383
|
-
|
384
|
-
**Original**
|
385
|
-
|
386
|
-
```ruby
|
387
|
-
Builtins.y2warning(msg)
|
388
|
-
```
|
389
|
-
|
390
|
-
**Translated**
|
391
|
-
|
392
|
-
```ruby
|
393
|
-
include Yast::Logger
|
394
|
-
log.warn msg
|
395
|
-
```
|
396
|
-
|
397
|
-
It doesn't convert a log with extra parameters
|
398
|
-
|
399
|
-
**Unchanged**
|
400
|
-
|
401
|
-
```ruby
|
402
|
-
Builtins.y2warning(msg, arg1, arg2)
|
403
|
-
```
|
404
|
-
|
405
|
-
It converts log with operator call
|
406
|
-
|
407
|
-
**Original**
|
408
|
-
|
409
|
-
```ruby
|
410
|
-
Builtins.y2warning(msg1 + msg2)
|
411
|
-
```
|
412
|
-
|
413
|
-
**Translated**
|
414
|
-
|
415
|
-
```ruby
|
416
|
-
include Yast::Logger
|
417
|
-
log.warn msg1 + msg2
|
418
|
-
```
|
419
|
-
|
420
|
-
It adds logger include to the class definition
|
421
|
-
|
422
|
-
**Original**
|
423
|
-
|
424
|
-
```ruby
|
425
|
-
class Foo
|
426
|
-
Builtins.y2error('foo')
|
427
|
-
end
|
428
|
-
```
|
429
|
-
|
430
|
-
**Translated**
|
431
|
-
|
432
|
-
```ruby
|
433
|
-
class Foo
|
434
|
-
include Yast::Logger
|
435
|
-
|
436
|
-
log.error "foo"
|
437
|
-
end
|
438
|
-
```
|
439
|
-
|
440
|
-
It adds logger include with correct indentation
|
441
|
-
|
442
|
-
**Original**
|
443
|
-
|
444
|
-
```ruby
|
445
|
-
class Foo
|
446
|
-
Builtins.y2error('foo')
|
447
|
-
end
|
448
|
-
```
|
449
|
-
|
450
|
-
**Translated**
|
451
|
-
|
452
|
-
```ruby
|
453
|
-
class Foo
|
454
|
-
include Yast::Logger
|
455
|
-
|
456
|
-
log.error "foo"
|
457
|
-
end
|
458
|
-
```
|
459
|
-
|
460
|
-
It does not add the logger include if already present
|
461
|
-
|
462
|
-
**Original**
|
463
|
-
|
464
|
-
```ruby
|
465
|
-
class Foo
|
466
|
-
include Yast::Logger
|
467
|
-
Builtins.y2error('foo')
|
468
|
-
end
|
469
|
-
```
|
470
|
-
|
471
|
-
**Translated**
|
472
|
-
|
473
|
-
```ruby
|
474
|
-
class Foo
|
475
|
-
include Yast::Logger
|
476
|
-
log.error "foo"
|
477
|
-
end
|
478
|
-
```
|
479
|
-
|
480
|
-
It adds the logger include after the parent class name if present
|
481
|
-
|
482
|
-
**Original**
|
483
|
-
|
484
|
-
```ruby
|
485
|
-
class Foo < Bar
|
486
|
-
Builtins.y2error('foo')
|
487
|
-
end
|
488
|
-
```
|
489
|
-
|
490
|
-
**Translated**
|
491
|
-
|
492
|
-
```ruby
|
493
|
-
class Foo < Bar
|
494
|
-
include Yast::Logger
|
495
|
-
|
496
|
-
log.error "foo"
|
497
|
-
end
|
498
|
-
```
|
499
|
-
|
500
|
-
It adds logger include once to a derived class in a module
|
501
|
-
|
502
|
-
**Original**
|
503
|
-
|
504
|
-
```ruby
|
505
|
-
module Yast
|
506
|
-
class TestClass < Module
|
507
|
-
def test
|
508
|
-
Builtins.y2error("foo")
|
509
|
-
Builtins.y2debug("foo")
|
510
|
-
end
|
511
|
-
end
|
512
|
-
end
|
513
|
-
```
|
514
|
-
|
515
|
-
**Translated**
|
516
|
-
|
517
|
-
```ruby
|
518
|
-
module Yast
|
519
|
-
class TestClass < Module
|
520
|
-
include Yast::Logger
|
521
|
-
|
522
|
-
def test
|
523
|
-
log.error "foo"
|
524
|
-
log.debug "foo"
|
525
|
-
end
|
526
|
-
end
|
527
|
-
end
|
528
|
-
```
|
529
|
-
|
530
|
-
It converts the single quoted format string to double quoted
|
531
|
-
|
532
|
-
**Original**
|
533
|
-
|
534
|
-
```ruby
|
535
|
-
Builtins.y2milestone('foo: %1', foo)
|
536
|
-
```
|
537
|
-
|
538
|
-
**Translated**
|
539
|
-
|
540
|
-
```ruby
|
541
|
-
include Yast::Logger
|
542
|
-
log.info "foo: #{foo}"
|
543
|
-
```
|
544
|
-
|
545
|
-
It escapes double quotes and interpolations
|
546
|
-
|
547
|
-
**Original**
|
548
|
-
|
549
|
-
```ruby
|
550
|
-
Builtins.y2milestone('"#{foo}"')
|
551
|
-
```
|
552
|
-
|
553
|
-
**Translated**
|
554
|
-
|
555
|
-
```ruby
|
556
|
-
include Yast::Logger
|
557
|
-
log.info "\\"\\#{foo}\\""
|
558
|
-
```
|
559
|
-
|
560
|
-
It does not convert logging with backtrace
|
561
|
-
|
562
|
-
**Unchanged**
|
563
|
-
|
564
|
-
```ruby
|
565
|
-
Builtins.y2milestone(-1, "foo")
|
566
|
-
```
|
567
|
-
|
568
|
-
It does not convert code with a local variable 'log'
|
569
|
-
|
570
|
-
**Unchanged**
|
571
|
-
|
572
|
-
```ruby
|
573
|
-
log = 1
|
574
|
-
Builtins.y2milestone("foo")
|
575
|
-
```
|
576
|
-
|
577
|
-
<!--
|
578
|
-
|
579
|
-
Template
|
580
|
-
--------
|
581
|
-
|
582
|
-
It finds an offense
|
583
|
-
|
584
|
-
**Offense**
|
585
|
-
|
586
|
-
```ruby
|
587
|
-
```
|
588
|
-
|
589
|
-
This code is OK
|
590
|
-
|
591
|
-
**Accepted**
|
592
|
-
|
593
|
-
```ruby
|
594
|
-
```
|
595
|
-
|
596
|
-
It translates.
|
597
|
-
|
598
|
-
**Original**
|
599
|
-
|
600
|
-
```ruby
|
601
|
-
```
|
602
|
-
|
603
|
-
**Translated**
|
604
|
-
|
605
|
-
```ruby
|
606
|
-
```
|
607
|
-
|
608
|
-
It does not translate.
|
609
|
-
|
610
|
-
**Unchanged**
|
611
|
-
|
612
|
-
```ruby
|
613
|
-
```
|
614
|
-
-->
|
data/spec/rspec_code.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
|
2
|
-
# this module provides code block generators for RSpecRenderer
|
3
|
-
module RspecCode
|
4
|
-
# rubocop:disable Metrics/MethodLength
|
5
|
-
def generate_translation_code
|
6
|
-
[
|
7
|
-
"original_code = code_cleanup(<<-EOT)",
|
8
|
-
Code.indent(@original_code),
|
9
|
-
"EOT",
|
10
|
-
"",
|
11
|
-
"translated_code = code_cleanup(<<-EOT)",
|
12
|
-
Code.indent(@translated_code),
|
13
|
-
"EOT",
|
14
|
-
"",
|
15
|
-
"cop = RuboCop::Cop::Yast::Builtins.new",
|
16
|
-
"expect(autocorrect_source(cop, original_code)).to eq(translated_code)"
|
17
|
-
].join("\n")
|
18
|
-
end
|
19
|
-
|
20
|
-
def generate_offense_code
|
21
|
-
[
|
22
|
-
"code = code_cleanup(<<-EOT)",
|
23
|
-
Code.indent(@offense),
|
24
|
-
"EOT",
|
25
|
-
"",
|
26
|
-
"cop = RuboCop::Cop::Yast::Builtins.new",
|
27
|
-
"inspect_source(cop, [code])",
|
28
|
-
"",
|
29
|
-
"expect(cop.offenses.size).to eq(1)",
|
30
|
-
"expect(cop.messages.first).to match(/Builtin call `.*` is obsolete/)"
|
31
|
-
].join("\n")
|
32
|
-
end
|
33
|
-
|
34
|
-
def generate_accepted_code
|
35
|
-
[
|
36
|
-
"code = code_cleanup(<<-EOT)",
|
37
|
-
Code.indent(@accepted_code),
|
38
|
-
"EOT",
|
39
|
-
"",
|
40
|
-
"cop = RuboCop::Cop::Yast::Builtins.new",
|
41
|
-
"inspect_source(cop, [code])",
|
42
|
-
"",
|
43
|
-
"expect(cop.offenses).to be_empty"
|
44
|
-
].join("\n")
|
45
|
-
end
|
46
|
-
# rubocop:enable Metrics/MethodLength
|
47
|
-
end
|
data/spec/rspec_renderer.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
require "redcarpet"
|
2
|
-
|
3
|
-
require_relative "rspec_code"
|
4
|
-
|
5
|
-
# Utility functions for manipulating code.
|
6
|
-
module Code
|
7
|
-
INDENT_STEP = 2
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def join(lines)
|
11
|
-
lines.map { |l| "#{l}\n" }.join("")
|
12
|
-
end
|
13
|
-
|
14
|
-
def indent(s)
|
15
|
-
s.gsub(/^(?=.)/, " " * INDENT_STEP)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# Represents RSpec's "it" block.
|
21
|
-
class It
|
22
|
-
def initialize(attrs)
|
23
|
-
@description = attrs[:description]
|
24
|
-
@code = attrs[:code]
|
25
|
-
@skip = attrs[:skip]
|
26
|
-
end
|
27
|
-
|
28
|
-
def render
|
29
|
-
[
|
30
|
-
"#{@skip ? "xit" : "it"} #{@description.inspect} do",
|
31
|
-
Code.indent(@code),
|
32
|
-
"end"
|
33
|
-
].join("\n")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Represents RSpec's "describe" block.
|
38
|
-
class Describe
|
39
|
-
attr_reader :blocks
|
40
|
-
|
41
|
-
def initialize(attrs)
|
42
|
-
@description = attrs[:description]
|
43
|
-
@blocks = attrs[:blocks]
|
44
|
-
end
|
45
|
-
|
46
|
-
def render
|
47
|
-
parts = []
|
48
|
-
parts << "describe #{@description.inspect} do"
|
49
|
-
parts << Code.indent(@blocks.map(&:render).join("\n\n")) if !blocks.empty?
|
50
|
-
parts << "end"
|
51
|
-
parts.join("\n")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Renders a Markdown file to an RSpec test script
|
56
|
-
class RSpecRenderer < Redcarpet::Render::Base
|
57
|
-
include RspecCode
|
58
|
-
|
59
|
-
IGNORED_HEADERS = [
|
60
|
-
"Table Of Contents",
|
61
|
-
"Description"
|
62
|
-
]
|
63
|
-
|
64
|
-
def initialize
|
65
|
-
super
|
66
|
-
|
67
|
-
@next_block_type = :unknown
|
68
|
-
@describe = Describe.new(description: "RuboCop-Yast", blocks: [])
|
69
|
-
end
|
70
|
-
|
71
|
-
# preprocess the MarkDown input - remove comments
|
72
|
-
def preprocess(fulldoc)
|
73
|
-
# use multiline regexp pattern
|
74
|
-
fulldoc.gsub(/<!--.*-->/m, "")
|
75
|
-
end
|
76
|
-
|
77
|
-
def header(text, header_level)
|
78
|
-
return nil if header_level == 1 || IGNORED_HEADERS.include?(text)
|
79
|
-
|
80
|
-
if header_level > describes_depth + 1
|
81
|
-
raise "Missing higher level header: #{text}"
|
82
|
-
end
|
83
|
-
|
84
|
-
describe_at_level(header_level - 1).blocks << Describe.new(
|
85
|
-
description: text + ":",
|
86
|
-
blocks: []
|
87
|
-
)
|
88
|
-
|
89
|
-
nil
|
90
|
-
end
|
91
|
-
|
92
|
-
def paragraph(text)
|
93
|
-
if text =~ /^\*\*(.*)\*\*$/
|
94
|
-
@next_block_type = Regexp.last_match[1].downcase.to_sym
|
95
|
-
else
|
96
|
-
first_sentence = text.split(/\.(\s+|$)/).first
|
97
|
-
@description = first_sentence.sub(/^RuboCop-Yast /, "").sub(/\n/, " ")
|
98
|
-
end
|
99
|
-
|
100
|
-
nil
|
101
|
-
end
|
102
|
-
|
103
|
-
# rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity:
|
104
|
-
def block_code(code, _language)
|
105
|
-
escaped_code = escape(code[0..-2])
|
106
|
-
|
107
|
-
case @next_block_type
|
108
|
-
when :original
|
109
|
-
@original_code = escaped_code
|
110
|
-
when :translated
|
111
|
-
@translated_code = escaped_code
|
112
|
-
when :unchanged
|
113
|
-
@original_code = @translated_code = escaped_code
|
114
|
-
when :offense
|
115
|
-
@offense = escaped_code
|
116
|
-
when :accepted
|
117
|
-
@accepted_code = escaped_code
|
118
|
-
else
|
119
|
-
raise "Invalid next code block type: #{@next_block_type}.\n#{code}"
|
120
|
-
end
|
121
|
-
|
122
|
-
@next_block_type = :unknown
|
123
|
-
|
124
|
-
add_translation_block if @original_code && @translated_code
|
125
|
-
add_offense_block if @offense
|
126
|
-
add_accepted_block if @accepted_code
|
127
|
-
|
128
|
-
nil
|
129
|
-
end
|
130
|
-
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity:
|
131
|
-
|
132
|
-
# escape ruby interpolation
|
133
|
-
def escape(code)
|
134
|
-
code.gsub("\#{", "\\\#{")
|
135
|
-
end
|
136
|
-
|
137
|
-
def doc_header
|
138
|
-
Code.join([
|
139
|
-
"# Automatically generated -- DO NOT EDIT!",
|
140
|
-
"",
|
141
|
-
"require \"spec_helper\"",
|
142
|
-
""
|
143
|
-
])
|
144
|
-
end
|
145
|
-
|
146
|
-
def doc_footer
|
147
|
-
"#{@describe.render}\n"
|
148
|
-
end
|
149
|
-
|
150
|
-
private
|
151
|
-
|
152
|
-
def describes_depth
|
153
|
-
describe = @describe
|
154
|
-
depth = 1
|
155
|
-
while describe.blocks.last.is_a?(Describe)
|
156
|
-
describe = describe.blocks.last
|
157
|
-
depth += 1
|
158
|
-
end
|
159
|
-
depth
|
160
|
-
end
|
161
|
-
|
162
|
-
def current_describe
|
163
|
-
describe = @describe
|
164
|
-
describe = describe.blocks.last while describe.blocks.last.is_a?(Describe)
|
165
|
-
describe
|
166
|
-
end
|
167
|
-
|
168
|
-
def describe_at_level(level)
|
169
|
-
describe = @describe
|
170
|
-
2.upto(level) do
|
171
|
-
describe = describe.blocks.last
|
172
|
-
end
|
173
|
-
describe
|
174
|
-
end
|
175
|
-
|
176
|
-
def add_translation_block
|
177
|
-
current_describe.blocks << It.new(
|
178
|
-
description: @description,
|
179
|
-
code: generate_translation_code,
|
180
|
-
skip: @description =~ /XFAIL/
|
181
|
-
)
|
182
|
-
|
183
|
-
@original_code = nil
|
184
|
-
@translated_code = nil
|
185
|
-
end
|
186
|
-
|
187
|
-
def add_offense_block
|
188
|
-
current_describe.blocks << It.new(
|
189
|
-
description: @description,
|
190
|
-
code: generate_offense_code,
|
191
|
-
skip: @description =~ /XFAIL/
|
192
|
-
)
|
193
|
-
|
194
|
-
@offense = nil
|
195
|
-
end
|
196
|
-
|
197
|
-
def add_accepted_block
|
198
|
-
current_describe.blocks << It.new(
|
199
|
-
description: @description,
|
200
|
-
code: generate_accepted_code,
|
201
|
-
skip: @description =~ /XFAIL/
|
202
|
-
)
|
203
|
-
|
204
|
-
@accepted_code = nil
|
205
|
-
end
|
206
|
-
end
|