Skip to content

Commit

Permalink
initial support for writing tests in cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Dec 12, 2014
1 parent bbd1738 commit 531384b
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 32 deletions.
5 changes: 4 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ rescue Bundler::BundlerError => e
exit e.status_code
end

require "cucumber/rake/task"
Cucumber::Rake::Task.new(:features)

require "redcarpet"
require_relative "spec/rspec_renderer"

Expand Down Expand Up @@ -40,4 +43,4 @@ task spec: ["spec/builtins_spec.rb"]
require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop)

task default: [:spec, :rubocop]
task default: [:spec, :features, :rubocop]
21 changes: 21 additions & 0 deletions features/builtins_cop.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Builtins Cop Features

Scenario: Builtins.y2milestone() is reported
Given the original code is "Builtins.y2milestone('foo')"
When I check it using RuboCop::Cop::Yast::Builtins cop
Then offense "Builtin call `y2milestone` is obsolete" is found

Scenario: Allowed Builtins.lsort() call is accepted
Given the original code is "Builtins.lsort([])"
When I check it using RuboCop::Cop::Yast::Builtins cop
Then the code is found correct

Scenario: Builtins in the ::Builtins name space are ignored
Given the original code is "::Builtins.lsort([])"
When I check it using RuboCop::Cop::Yast::Builtins cop
Then the code is found correct

Scenario: Unknown Builtins call is not changed
Given the original code is "Builtins.foo()"
When I correct it using RuboCop::Cop::Yast::Builtins cop
Then the code is unchanged
5 changes: 5 additions & 0 deletions features/builtins_time.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Builtins.time()
Scenario: Replace Builtins.time() with ::Time.now.to_i
Given the original code is "Builtins.time()"
When I correct it using RuboCop::Cop::Yast::Builtins cop
Then the code should be converted to "::Time.now.to_i"
15 changes: 15 additions & 0 deletions features/builtins_y2log.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Logging Builtins

Scenario: The include statement is added only once
Given the original code is
"""
Builtins.y2milestone("foo")
Builtins.y2milestone("foo")
"""
When I correct it using RuboCop::Cop::Yast::Builtins cop
Then the code should be converted to
"""
include Yast::Logger
log.info "foo"
log.info "foo"
"""
42 changes: 42 additions & 0 deletions features/step_definitions/cop_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# inline code
Given(/^the original code is "(.*)"$/) do |original_code|
@original_code = original_code
end

# multiline code passed via docstring
Given(/^the original code is$/) do |original_code|
@original_code = original_code
end

When(/^I correct it using (.*) cop$/) do |cop|
@cop = Object.const_get(cop).new
@corrected = autocorrect_source(@cop, @original_code.split("\n"))
end

# inline code
Then(/^the code should be converted to "(.*)"$/) do |expected_code|
expect(@corrected).to eq(expected_code)
end

# multiline code passed via docstring
Then(/^the code should be converted to$/) do |expected_code|
expect(@corrected).to eq(expected_code)
end

Then(/^the code is unchanged$/) do
expect(@corrected).to eq(@original_code)
end

When(/^I check it using (.*) cop$/) do |cop|
@cop = Object.const_get(cop).new
inspect_source(@cop, @original_code.split("\n"))
end

Then(/^the code is found correct$/) do
expect(@cop.offenses).to be_empty
end

Then(/^offense "(.*)" is found$/) do |offense|
expect(@cop.offenses.first.message).to include(offense)
end
36 changes: 36 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# encoding: utf-8

require "simplecov"
require "rspec"

# use coveralls for on-line code coverage reporting at Travis CI
if ENV["TRAVIS"]
require "coveralls"

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
end

SimpleCov.start do
# don't check code coverage in these subdirectories
add_filter "/vendor/"
add_filter "/features/"
end

# allow only the new "expect" RSpec syntax
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
end

# reuse the Rubocop helper, provides some nice methods used in tests
require File.join(Gem::Specification.find_by_name("rubocop").gem_dir, "spec",
"support", "cop_helper.rb")
include CopHelper

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))

require "rubocop-yast"
1 change: 1 addition & 0 deletions rubocop-yast.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("rake")
spec.add_development_dependency("redcarpet", "~> 3")
spec.add_development_dependency("rspec", "~> 3.1.0")
spec.add_development_dependency("cucumber")
spec.add_development_dependency("simplecov")
end
19 changes: 0 additions & 19 deletions spec/builtins_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Table Of Contents
-----------------

1. [Description](#description)
1. [Builtins.time()](#builtinstime)
1. [Builtins.getenv()](#builtinsgetenv)
1. [Logging - Builtins.y2debug(),...](#logging---builtinsy2debug-)

Expand Down Expand Up @@ -82,24 +81,6 @@ It does not change unknown builtins
Builtins.foo()
```


Builtins.time()
---------------

Is trivially converted to `::Time.now.to_i`

**Original**

```ruby
Builtins.time()
```

**Translated**

```ruby
::Time.now.to_i
```

Builtins.getenv()
-----------------

Expand Down
12 changes: 0 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

require "simplecov"

# use coveralls for on-line code coverage reporting at Travis CI
if ENV["TRAVIS"]
require "coveralls"

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
end

SimpleCov.minimum_coverage 95

SimpleCov.start do
# don't check code coverage in these subdirectories
add_filter "/vendor/"
Expand Down

0 comments on commit 531384b

Please sign in to comment.