-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fedor Barannik
committed
May 16, 2017
1 parent
c2ebd20
commit f47b21f
Showing
11 changed files
with
195 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
--color | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
require 'pry' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec | ||
|
||
desc 'Post test case structure to the test management for jira' | ||
task :create_tests | ||
|
||
RSpec::Core::RakeTask.new(:create_tests) do |t| | ||
t.rspec_opts = ['--dry-run', '-r ./rspec_config'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'rspec/core/formatters/base_formatter' | ||
|
||
RSpec.configuration.add_setting :tmj_create_test_formatter_options, default: {} | ||
|
||
class TMJCreateTestFormatter < RSpec::Core::Formatters::BaseFormatter | ||
DEFAULT_CREATE_TEST_FORMATTER_OPTIONS = { update_existing_tests: false, test_owner: nil, custom_labels: nil}.freeze | ||
|
||
RSpec::Core::Formatters.register self, :start, :example_started | ||
|
||
def start(_notification) | ||
@options = DEFAULT_CREATE_TEST_FORMATTER_OPTIONS.merge(RSpec.configuration.tmj_create_test_formatter_options) | ||
@client = TMJ::Client.new | ||
end | ||
|
||
def example_started(notification) | ||
return if notification.example.metadata.has_key?(:test_id) && !notification.example.metadata[:test_id].empty? | ||
|
||
begin | ||
response = @client.TestCase.create(process_example(notification.example)) | ||
raise TMJ::TestCaseError, response unless response.code == 201 | ||
rescue => e | ||
puts e, e.message | ||
exit | ||
end | ||
|
||
update_local_test(notification.example, response['key']) | ||
end | ||
|
||
private | ||
|
||
def update_local_test(example, test_key) | ||
lines = File.readlines(example.metadata[:file_path]) | ||
lines[line_number(example)].gsub!("test_id: ''", "test_id: '#{test_key}'") | ||
File.open(example.metadata[:file_path], 'w') { |f| f.write(lines.join) } | ||
end | ||
|
||
def line_number(example) | ||
example.metadata[:line_number]-1 | ||
end | ||
|
||
def process_example(example) | ||
{ | ||
"projectKey": "#{TMJ.config.project_id}", | ||
"name": "#{example.metadata[:description]}", | ||
"precondition": "#{example.metadata[:precondition]}", | ||
"owner": "#{@options[:test_owner]}", | ||
"labels": @options[:custom_labels], | ||
"testScript": { | ||
"type": "STEP_BY_STEP", | ||
"steps": process_steps(example.metadata[:steps]) | ||
} | ||
}.delete_if { |k, v| v.nil? || v.empty?} | ||
end | ||
|
||
def process_steps(examole) | ||
arr = [] | ||
examole.each { |s| arr << {"description": s[:step_name]} } | ||
arr | ||
end | ||
|
||
end | ||
|
||
# TODO: be able to update test case. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
require 'tmj_ruby' | ||
require 'rspec' | ||
|
||
require 'tmj_formatter/version' | ||
require 'tmj_formatter/version' | ||
require_relative 'tmj_formatter/steps' | ||
require_relative 'tmj_formatter/adapter' | ||
|
||
require_relative 'tmj_output_formatter' | ||
require_relative 'tmj_result_formatter' | ||
require_relative 'tmj_result_formatter' | ||
require_relative 'tmj_create_test_formatter' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# TODO: Figure out a better way to patch this | ||
|
||
module RSpec | ||
module Core | ||
class Example | ||
def run(example_group_instance, reporter) | ||
@example_group_instance = example_group_instance | ||
@reporter = reporter | ||
RSpec.configuration.configure_example(self, hooks) | ||
RSpec.current_example = self | ||
|
||
if RSpec.configuration.dry_run? | ||
@metadata[:step_index] = 0 | ||
@example_group_instance.instance_exec(self, &@example_block) | ||
end | ||
|
||
start(reporter) | ||
Pending.mark_pending!(self, pending) if pending? | ||
begin | ||
if skipped? | ||
Pending.mark_pending! self, skip | ||
elsif !RSpec.configuration.dry_run? | ||
with_around_and_singleton_context_hooks do | ||
begin | ||
run_before_example | ||
@example_group_instance.instance_exec(self, &@example_block) | ||
|
||
if pending? | ||
Pending.mark_fixed! self | ||
|
||
raise Pending::PendingExampleFixedError, | ||
'Expected example to fail since it is pending, but it passed.', | ||
[location] | ||
end | ||
rescue Pending::SkipDeclaredInExample => _ | ||
# The "=> _" is normally useless but on JRuby it is a workaround | ||
# for a bug that prevents us from getting backtraces: | ||
# https://github.com/jruby/jruby/issues/4467 | ||
# | ||
# no-op, required metadata has already been set by the `skip` | ||
# method. | ||
rescue AllExceptionsExcludingDangerousOnesOnRubiesThatAllowIt => e | ||
set_exception(e) | ||
ensure | ||
run_after_example | ||
end | ||
end | ||
end | ||
rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e | ||
set_exception(e) | ||
ensure | ||
@example_group_instance = nil # if you love something... let it go | ||
end | ||
|
||
finish(reporter) | ||
ensure | ||
execution_result.ensure_timing_set(clock) | ||
RSpec.current_example = nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'tmj_formatter' | ||
require_relative 'lib/tmj_formatter/example' | ||
|
||
class RspecConfig | ||
RSpec.configure do |c| | ||
c.color = true | ||
c.formatter = 'TMJCreateTestFormatter' | ||
c.tmj_create_test_formatter_options = { update_existing_tests: true, test_owner: 'test', custom_labels: ['automated'] } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "spec_helper" | ||
|
||
PRECONDITION = 'PROVIDE SOME DATA HERE' | ||
|
||
RSpec.describe 'Test Case' do | ||
it 'Test Example From Local', precondition: PRECONDITION, test_id: 'CC-T1444' do |e| | ||
e.step 'test' do | ||
end | ||
|
||
e.step 'test 2' do | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters