Skip to content

Instantly share code, notes, and snippets.

View enkessler's full-sized avatar

Eric Kessler enkessler

View GitHub Profile
@enkessler
enkessler / make_it_work.rb
Last active November 3, 2018 20:05
Custom gherkin dialect
require 'gherkin/gherkin'
require 'gherkin/dialect'
test_dialects = JSON.parse(File.open('test_languages.json', 'r:UTF-8').read)
Gherkin::DIALECTS.merge!(test_dialects)
source_text = File.read('something_to_parse.feature')
result = Gherkin::Gherkin.from_source('junk_file_name', source_text, {default_dialect: 'cm-test'}).to_a
puts "messages returned: #{result.count}"
@enkessler
enkessler / my_steps.rb
Last active October 18, 2017 22:58
Data table corruption example
When(/^whatever we have too much of in the back room:$/) do |table|
$stdout.puts "starting table:\n#{table}"
$stdout.puts "id: #{table.rows_hash.object_id}"
@todays_sauce = ['ketchup', 'mustard', 'vinegar', 'mayo', 'lard'].sample
table.rows_hash['recipe'].sub!('<sauce of the day>', @todays_sauce)
@recipe = table.rows_hash['recipe']
$stdout.puts "ending table:\n#{table}"
@enkessler
enkessler / a.feature
Created May 24, 2017 12:26
Gist for reproducing Cucumber issue
Feature:
Scenario: test 1
* a step
* an ambiguous step
Scenario: test 2
* step 1
* step 2
@enkessler
enkessler / run_first_scenarios.rb
Created October 20, 2016 19:02
Example code for running certain Cucumber tests
require 'cql'
# Model your suite
path_to_test_suite_directory = File.dirname(__FILE__)
suite_model = CQL::Repository.new(path_to_test_suite_directory)
# Gather the first scenario of every feature
results = suite_model.query do
select :model
@enkessler
enkessler / async.feature
Last active August 24, 2020 07:56
This gist demonstrates one way to write a Cucumber scenario that tests an asynchronous feature. It is essentially a two part test but it maintains the documentation value of a single, cohesive test.
Feature: Testing an asynchronous thing
@async @batch_1
Scenario: Some big batch process
Given some stuff is set up
When the thing happens
Then it worked
@async @batch_2
Scenario: Another big batch process
@enkessler
enkessler / my_steps.rb
Created September 22, 2015 13:02
Cucumber output bug
And(/^do a thing$/) do
foo = 'a'
puts foo # Should output 'a'
foo.upcase!
puts foo # Should output 'A'
foo = 'b'
puts foo # Should output 'b'
end
@enkessler
enkessler / feature_1.feature
Last active August 29, 2015 14:17
Randomizing Cucumber outlines
Feature: Feature 1
Scenario: A normal test
* foo
@Random(50)
Scenario Outline:
* foo
Examples:
| values |
@enkessler
enkessler / env.rb
Created September 11, 2013 03:29
An example usage of the cucumber_analytics gem to add a unique identifier to every test case in a test suite. By making the identifier part of the test case itself it should be accessible both at run time via Cucumber's scenario object and from a static inspection of the source code by anything that can parse gherkin (e.g. cucumber_analytics).
require_relative '../../unique_test_case_tagger'
DEFAULT_FEATURE_FILE_NAME = 'test_feature'
DEFAULT_FILE_DIRECTORY = "#{File.dirname(__FILE__)}/../temp_files"
Before do
@default_feature_file_name = DEFAULT_FEATURE_FILE_NAME
@default_file_directory = DEFAULT_FILE_DIRECTORY
@enkessler
enkessler / lexicon.rb
Last active February 11, 2017 15:39
An example usage of the cucumber_analytics, cuke_modeler, and other associated gems to create a lexicon of the steps used in a test suite.
require 'fileutils'
require 'cucumber_analytics'
require 'cuke_modeler'
require 'cql'
require 'cql/model_dsl'
# Project structure setup
your_location_here = "#{File.dirname(__FILE__)}/.."
feature_directory = "#{your_location_here}/features"
@enkessler
enkessler / gem_extensions.rb
Created May 9, 2013 19:07
Recreating a step smelling bug in cuke_sniffer.
module CukeSniffer
module RuleConfig
FATAL = 100 #will prevent suite from executing properly
ERROR = 25 #will cause problem with debugging
WARNING = 10 #readibility/misuse of cucumber
INFO = 1 #Small improvements that can be made
OUR_RULES = {
:something_wrong => {