Skip to content

Commit

Permalink
Handle Rules better
Browse files Browse the repository at this point in the history
Updated the test framework so that it can easily exclude tests for
features that only certain versions of CukeModeler have. Also, updated
FeatureWithoutScenariosLinter to work with older versions of CukeModeler.
  • Loading branch information
enkessler committed May 21, 2022
1 parent ac61697 commit 68ccbb8
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
14 changes: 12 additions & 2 deletions cucumber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
<% require "#{__dir__}/cuke_linter_project_settings" %>

<% FileUtils.mkdir(ENV['CUKE_LINTER_REPORT_FOLDER']) unless File.exist?(ENV['CUKE_LINTER_REPORT_FOLDER'])%>
<% cucumber_major_version = Gem.loaded_specs['cucumber'].version.version.match(/^(\d+)\./)[1].to_i %>
<%
cucumber_major_version = Gem.loaded_specs['cucumber'].version.version.match(/^(\d+)\./)[1].to_i
cuke_modeler_major_version = Gem.loaded_specs['cuke_modeler'].version.version.match(/^(\d+)\./)[1].to_i
max_cuke_modeler_version = ENV['MOST_CURRENT_CUKE_MODELER_VERSION'].to_i
%>

common: -r testing/environments/cucumber_env.rb -t <%= cucumber_major_version < 4 ? "~@wip": "'not @wip'" %> <%= '--publish-quiet' if cucumber_major_version >= 5 %> -f progress --color -p json
<%
# Some tests only work for some versions of CukeModeler
cuke_modeler_filter_tags = ((cuke_modeler_major_version + 1)..max_cuke_modeler_version).map{ |index| "@cuke_modeler_min_version_#{index}" }
formatted_filter_tags = (cucumber_major_version < 4 ? cuke_modeler_filter_tags.map { |tag| "-t ~#{tag}" } : cuke_modeler_filter_tags.map { |tag| "-t 'not #{tag}'" }).join(' ')
%>

common: -r testing/environments/cucumber_env.rb -t <%= cucumber_major_version < 4 ? "~@wip": "'not @wip'" %> <%= '--publish-quiet' if cucumber_major_version >= 5 %> <%= formatted_filter_tags unless cuke_modeler_major_version == max_cuke_modeler_version %> -f progress --color -p json

# Using the HTML formatter causes a bug with some versions of Cucumber, for some reason
html: -f html -o <%= ENV['CUKE_LINTER_CUCUMBER_REPORT_HTML_FILE_PATH'] %>
Expand Down
2 changes: 2 additions & 0 deletions cuke_linter_project_settings.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# rubocop:disable Metrics/LineLength
ENV['MOST_CURRENT_CUKE_MODELER_VERSION'] ||= '3'

ENV['CUKE_LINTER_PARALLEL_RUN'] ||= 'false'
ENV['CUKE_LINTER_REPORT_FOLDER'] ||= "#{__dir__}/reports"

Expand Down
3 changes: 2 additions & 1 deletion lib/cuke_linter/linters/feature_without_scenarios_linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def rule(model)
return false unless model.is_a?(CukeModeler::Feature)

feature_tests = model.tests && model.tests.any?
rule_tests = model.rules && model.rules.any?{|rule| rule.tests && rule.tests.any?}
rule_tests = model.respond_to?(:rules) && # Earlier versions of CukeModeler did not have Rule models
model.rules && model.rules.any? { |rule| rule.tests && rule.tests.any? }

!(feature_tests || rule_tests)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Feature: Feature without scenarios linter
When it is linted
Then no error is reported

@cuke_modeler_min_version_3
Scenario: Linting (Good, with Rules)
Given a linter for features without scenarios
And the following feature:
Expand Down
2 changes: 2 additions & 0 deletions testing/environments/common_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
require_relative '../linter_factory'
require_relative '../formatter_factory'
require_relative '../file_helper'
require_relative '../helper_methods'

PROJECT_ROOT = "#{__dir__}/../..".freeze
MOST_CURRENT_CUKE_MODELER_VERSION = ENV['MOST_CURRENT_CUKE_MODELER_VERSION'].to_i
4 changes: 4 additions & 0 deletions testing/environments/rspec_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
end
end

# Methods will be available outside of tests
include CukeLinter::HelperMethods

# Methods will be available inside of tests
config.include CukeLinter::FileHelper
config.include CukeLinter::FormatterFactory
config.include CukeLinter::LinterFactory
Expand Down
16 changes: 16 additions & 0 deletions testing/helper_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module CukeLinter

# Some helper methods used during testing
module HelperMethods

def cuke_modeler?(versions)
versions = [versions] unless versions.is_a?(Enumerable)
versions.include?(cuke_modeler_major_version)
end

def cuke_modeler_major_version
Gem.loaded_specs['cuke_modeler'].version.version.match(/^(\d+)\./)[1].to_i
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

end

context 'and no nested tests' do
context 'and no nested tests', if: cuke_modeler?((3..MOST_CURRENT_CUKE_MODELER_VERSION)) do

context 'because it has no rules' do

Expand Down Expand Up @@ -178,7 +178,7 @@

end

context 'with a rule' do
context 'with a rule', if: cuke_modeler?((3..MOST_CURRENT_CUKE_MODELER_VERSION)) do

context 'that has a scenario' do

Expand Down Expand Up @@ -213,7 +213,7 @@

end

context 'with multiple rules' do
context 'with multiple rules', if: cuke_modeler?((3..MOST_CURRENT_CUKE_MODELER_VERSION)) do

let(:test_model) do
gherkin = 'Feature:
Expand Down

0 comments on commit 68ccbb8

Please sign in to comment.