atm_formatter 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fabfbc07dbbb33ffae5b909e461d144adc8771f6
4
+ data.tar.gz: f311f2248ea8b69dbcc4607541dd37bbc21c64be
5
+ SHA512:
6
+ metadata.gz: 818939a1df48e5d19670b9bf96cbc279d6e9ce4f37f523516b76b0421f47e33fbafa53b0aff26ab69cbd0adbeaa1e1575a5a8f30e2088cd0a23b93efe0e979ad
7
+ data.tar.gz: b5eed0e1e32d0ad7c54191a418385b679dc1315dc3ffa6bf3e223ef92057405aa941080f35cfdb16e4295715fc46b8c402fa962a7d995a332811adfb4fab3ab4
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+
3
+
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
6
+ deploy:
7
+ provider: rubygems
8
+ api_key:
9
+ secure: FD094gf79fXIEokEmgUzYpjH504oT/D6IfF+TclBliOgxx4Ksr7rMXxQF9RCjGaQxgNxPww3i9RlzPbbL0uPCcghq8aRhmWdTcuUJf2vtmgXFXoo49i6DoguwjLKojxNWmlczqzL9P3BTpXL9G2udwlKSvbzBn2MJ+cIl450qUoXSh63VclM5FHPYA57xStB5WUJfOtDzJ6k6kjnDbmOk1+//4+fnnVb6G19LsxOQdE10r3jovGP7pkdH4ukuftiJoyr+QmRX8vvePEbq93CakwypCXkZRThWqtB9LD9gGiFFe5S7HlKQDfujI+wX54rpIO1PspJvMNbT31Ylnv3urd0FTctrqBA2Z5MEpJGC73AG4LsEI7xpifwUgE3lUFKu2aLwzIFvpraypj7OPRUC2NQ8S/fzgJ4+an4oUmp7AtNOErh86hh7hGb0ZWlCOmwDazklrioaDweTeyqTusNOKIC5/gnue84EOC2POJGKfMX9RjqV1eEMStMHs6GI+vEBqjUEeV01ruB/QwhNo/KDFHJLFkt5+pb2CO/fF6E43lhsezK94+GHETFr805ExSLoswo+dKeVjLzGoUz2SVTOw8L/toe10KCrrMCxcboec+aRZ8HHPJH8JiVUzXrk7BtVlJi9qqWNrcKtcm+lpVdVcd3RJwWU2sQMlmkEVEg7hk=
10
+ gem: atm_formatter
11
+ on:
12
+ tags: true
13
+ repo: automation-wizards/atm_formatter
14
+ branch: master
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at fedor.barannik@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in atm_formatter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Fedor Barannik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Rspec Formatter For Adaptavist Test Management
2
+ [![Gem Version](https://badge.fury.io/rb/atm_formatter.svg)](https://badge.fury.io/rb/atm_formatter)
3
+ [![Build Status](https://travis-ci.org/automation-wizards/atm_formatter.svg?branch=master)](https://travis-ci.org/automation-wizards/atm_formatter)
4
+ [![Coverage Status](https://coveralls.io/repos/github/automation-wizards/atm_formatter/badge.svg?branch=master)](https://coveralls.io/github/automation-wizards/atm_formatter?branch=master)
5
+ [![Inline docs](http://inch-ci.org/github/automation-wizards/atm_formatter.svg?branch=master)](http://inch-ci.org/github/automation-wizards/atm_formatter)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/automation-wizards/atm_formatter.svg)](https://gemnasium.com/github.com/automation-wizards/atm_formatter)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'atm_formatter'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install atm_formatter
23
+
24
+ ## Usage
25
+
26
+ #### Configuration
27
+ For more information refer to the [wiki](https://github.com/automation-wizards/atm_formatter/wiki)
28
+
29
+ ```ruby
30
+ ATMFormatter.configure do |c|
31
+ c.base_url = 'https://localhost'
32
+ c.auth_type = :basic
33
+ c.project_id = 'CC'
34
+ c.test_run_id = 'CC-R180'
35
+ c.environment = "".upcase
36
+ c.username = 'Test'
37
+ c.password = 'Test'
38
+ c.result_formatter_options = { run_only_found_tests: false, post_results: false }
39
+ c.create_test_formatter_options = { update_existing_tests: true,
40
+ test_owner: 'Test',
41
+ custom_labels: ['automated'] }
42
+ end
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/atm_formatter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require_relative 'lib/atm_formatter/tasks/test_manipulation_tasks'
4
+
5
+ require 'pry'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'atm_formatter/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'atm_formatter'
9
+ spec.version = ATMFormatter::VERSION
10
+ spec.authors = ['azohra']
11
+ spec.email = ['']
12
+
13
+ spec.summary = 'Write a short summary, because Rubygems requires one.'
14
+ spec.description = 'Write a longer description or delete this line.'
15
+ spec.homepage = 'https://github.com/azohra/atm_formatter'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_runtime_dependency 'atm_ruby', '~> 0.1.0'
26
+ spec.add_runtime_dependency 'rspec', '~> 3.0'
27
+ spec.add_runtime_dependency 'ruby-progressbar', '~> 1.8', '>= 1.8.1'
28
+ spec.add_development_dependency 'bundler', '~> 1.14'
29
+ spec.add_development_dependency 'rake', '~> 12.0'
30
+ spec.add_development_dependency 'coveralls', '~> 0.8.20'
31
+ spec.add_development_dependency 'pry', '~> 0.10.4'
32
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'atm_formatter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require_relative 'atm_formatter/helpers/base_formatter'
2
+
3
+ class ATMCreateTestFormatter < ATMFormatter::BaseFormatter
4
+ RSpec::Core::Formatters.register self, *NOTIFICATIONS
5
+
6
+ def example_started(notification)
7
+ if (notification.example.metadata.key?(:test_id) && !notification.example.metadata[:test_id].strip.empty?) || !notification.example.metadata.key?(:test_id)
8
+ return
9
+ end
10
+
11
+ response = @client.TestCase.create(process_example(notification.example))
12
+ if response.code != 201
13
+ puts ATM::TestCaseError.new(response).message
14
+ exit
15
+ end
16
+
17
+ update_local_test(notification.example, response['key'])
18
+ end
19
+
20
+ private
21
+
22
+ def update_local_test(example, test_key)
23
+ lines = File.readlines(example.metadata[:file_path])
24
+ lines[line_number(example)].gsub!(/test_id:(\s+)?('|")(\s+)?('|")/, "test_id: '#{test_key}'")
25
+ File.open(example.metadata[:file_path], 'w') { |f| f.write(lines.join) }
26
+ end
27
+
28
+ def line_number(example)
29
+ example.metadata[:line_number] - 1
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ require 'atm_ruby'
2
+ require 'rspec'
3
+
4
+ require 'atm_formatter/version'
5
+ require_relative 'configuration'
6
+ require_relative 'atm_formatter/steps'
7
+ require_relative 'atm_formatter/adapter'
8
+
9
+ require_relative 'atm_output_formatter'
10
+ require_relative 'atm_result_formatter'
11
+ require_relative 'atm_create_test_formatter'
12
+ require_relative 'atm_update_test_formatter'
@@ -0,0 +1,5 @@
1
+ module ATMFormatter
2
+ module Adaptor
3
+ RSpec::Core::Example.send :include, ATMFormatter::Example
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ # TODO: Figure out a better way to patch this
2
+ module RSpec
3
+ module Core
4
+ class Example
5
+ def run(example_group_instance, reporter)
6
+ @example_group_instance = example_group_instance
7
+ @reporter = reporter
8
+ RSpec.configuration.configure_example(self, hooks)
9
+ RSpec.current_example = self
10
+
11
+ if RSpec.configuration.dry_run?
12
+ @metadata[:step_index] = 0
13
+ @example_group_instance.instance_exec(self, &@example_block)
14
+ end
15
+
16
+ start(reporter)
17
+ Pending.mark_pending!(self, pending) if pending?
18
+ begin
19
+ if skipped?
20
+ Pending.mark_pending! self, skip
21
+ elsif !RSpec.configuration.dry_run?
22
+ with_around_and_singleton_context_hooks do
23
+ begin
24
+ run_before_example
25
+ @example_group_instance.instance_exec(self, &@example_block)
26
+
27
+ if pending?
28
+ Pending.mark_fixed! self
29
+
30
+ raise Pending::PendingExampleFixedError,
31
+ 'Expected example to fail since it is pending, but it passed.',
32
+ [location]
33
+ end
34
+ rescue Pending::SkipDeclaredInExample => _
35
+ # The "=> _" is normally useless but on JRuby it is a workaround
36
+ # for a bug that prevents us from getting backtraces:
37
+ # https://github.com/jruby/jruby/issues/4467
38
+ #
39
+ # no-op, required metadata has already been set by the `skip`
40
+ # method.
41
+ rescue AllExceptionsExcludingDangerousOnesOnRubiesThatAllowIt => e
42
+ set_exception(e)
43
+ ensure
44
+ run_after_example
45
+ end
46
+ end
47
+ end
48
+ rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e
49
+ set_exception(e)
50
+ ensure
51
+ @example_group_instance = nil # if you love something... let it go
52
+ end
53
+
54
+ finish(reporter)
55
+ ensure
56
+ execution_result.ensure_timing_set(clock)
57
+ RSpec.current_example = nil
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,45 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+ module ATMFormatter
3
+ class BaseFormatter < RSpec::Core::Formatters::BaseFormatter
4
+ DEFAULT_OPTIONS = { update_existing_tests: false, test_owner: nil, custom_labels: nil}.freeze
5
+
6
+ NOTIFICATIONS = %i[start, example_started].freeze
7
+
8
+ def start(_notification)
9
+ @options = DEFAULT_OPTIONS.merge(ATMFormatter.config.create_test_formatter_options)
10
+ @client = ATM::Client.new(ATMFormatter.config.to_hash)
11
+ end
12
+
13
+ private
14
+
15
+ def process_example(example)
16
+ {
17
+ "projectKey": configure_project_key,
18
+ "name": example.metadata[:full_description],
19
+ "objective": example.metadata[:objective],
20
+ "precondition": example.metadata[:precondition],
21
+ "folder": example.metadata[:folder],
22
+ "status": example.metadata[:status],
23
+ "priority": example.metadata[:priority],
24
+ "owner": @options[:test_owner],
25
+ "labels": @options[:custom_labels],
26
+ "testScript": process_steps(example.metadata[:steps])
27
+ }.delete_if { |k, v| v.nil? || v.empty?}
28
+ end
29
+
30
+
31
+ def configure_project_key
32
+ self.class.to_s == 'ATMUpdateTestFormatter' ? nil : ATMFormatter.config.project_id
33
+ end
34
+
35
+ def process_steps(example)
36
+ return unless example
37
+ arr = []
38
+ example.each { |s| arr << {"description": s[:step_name]} }
39
+ {
40
+ "type": "STEP_BY_STEP",
41
+ "steps": arr
42
+ }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ module ATMFormatter
2
+ module Example
3
+ def step(step, _options = {}, &block)
4
+ @metadata[:steps] = [] if @metadata[:steps].nil?
5
+ if RSpec.configuration.dry_run?
6
+ @metadata[:steps].push(step_name: step, index: @metadata[:step_index])
7
+ else
8
+ begin
9
+ yield block
10
+ @metadata[:steps].push(step_name: step, index: @metadata[:step_index], status: 'Pass')
11
+ rescue => e
12
+ @metadata[:steps].push(step_name: step, index: @metadata[:step_index], status: 'Fail', comment: process_exception(e))
13
+ raise
14
+ end
15
+ end
16
+ ensure @metadata[:step_index] += 1 if @metadata.key?(:step_index)
17
+ end
18
+
19
+ private
20
+
21
+ def process_exception(exception)
22
+ exception.is_a?(RSpec::Expectations::MultipleExpectationsNotMetError) ? format_exception(exception) : exception
23
+ end
24
+
25
+ def format_exception(exception)
26
+ exception.failures.join('<br />').gsub("\n", '<br />')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ require 'rake'
2
+ require 'atm_ruby'
3
+ require 'ruby-progressbar'
4
+
5
+ module ATM
6
+ class CreateTestFormatter
7
+ include Rake::DSL if defined? Rake::DSL
8
+ class << self
9
+ def install_tasks
10
+ new.install
11
+ end
12
+ end
13
+
14
+ def install
15
+ namespace 'atm' do
16
+ desc 'Create test cases with steps on Adaptavist Test Management'
17
+ task :create_with_steps, [:path] do |_t, args|
18
+ exec("bundle exec rspec #{args[:path] if args[:path]} --format ATMCreateTestFormatter --dry-run -r atm_formatter/example")
19
+ end
20
+
21
+ desc 'Create test cases on Adaptavist Test Management'
22
+ task :create, [:path] do |_t, args|
23
+ exec("bundle exec rspec #{args[:path] if args[:path]} --format ATMCreateTestFormatter --dry-run")
24
+ end
25
+
26
+ desc 'Update test cases with steps on Adaptavist Test Management'
27
+ task :update_with_steps, [:path] do |_t, args|
28
+ exec("bundle exec rspec #{args[:path] if args[:path]} --format ATMUpdateTestFormatter --dry-run -r atm_formatter/example")
29
+ end
30
+
31
+ desc 'Update test cases on Adaptavist Test Management'
32
+ task :update, [:path] do |_t, args|
33
+ exec("bundle exec rspec #{args[:path] if args[:path]} --format ATMUpdateTestFormatter --dry-run")
34
+ end
35
+
36
+ desc 'Upload saved test results'
37
+ task :upload, %i[url username password file_path] do |_t, args|
38
+ client = ATM::Client.new(base_url: args[:url], username: args[:username], password: args[:password], auth_type: :basic)
39
+ files = args[:file_path] ? Dir.glob(args[:file_path]) : Dir.glob('test_results/*.json')
40
+
41
+ files.each do |my_text_file|
42
+ puts "working on: #{my_text_file}..."
43
+ File.open(my_text_file, 'r') do |_test_case_data|
44
+ file_data = JSON.parse(File.read(my_text_file))
45
+ progressbar = ProgressBar.create(total: file_data['test_cases'].size, format: 'Progress %c/%C |%B| %a')
46
+ file_data['test_cases'].each do |test_case|
47
+ test_run_id = test_case.delete('test_run_id')
48
+ test_case_id = test_case.delete('test_case') if test_run_id
49
+
50
+ if test_run_id
51
+ client.TestRun.create_new_test_run_result(test_run_id, test_case_id, test_case.to_json)
52
+ progressbar.increment
53
+ else
54
+ warn('Have to run against test run')
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ ATM::CreateTestFormatter.install_tasks
@@ -0,0 +1,3 @@
1
+ module ATMFormatter
2
+ VERSION = '0.1.31'.freeze
3
+ end
@@ -0,0 +1,82 @@
1
+ require 'rspec/core/formatters/base_text_formatter'
2
+
3
+ class ATMOutputFormatter < RSpec::Core::Formatters::BaseTextFormatter
4
+ RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished,
5
+ :example_passed, :example_pending, :example_failed, :example_started
6
+
7
+ def initialize(output)
8
+ super
9
+ @group_level = 0
10
+ end
11
+
12
+ def example_started(notification)
13
+ notification.example.metadata[:step_index] = 0
14
+ end
15
+
16
+ def example_group_started(notification)
17
+ output.puts if @group_level.zero?
18
+ output.puts "#{current_indentation}#{notification.group.description.strip}"
19
+
20
+ @group_level += 1
21
+ end
22
+
23
+ def example_group_finished(_notification)
24
+ @group_level -= 1
25
+ end
26
+
27
+ def example_passed(passed)
28
+ passed_output(passed.example)
29
+ end
30
+
31
+ def example_pending(pending)
32
+ pending_output(pending.example,
33
+ pending.example.execution_result.pending_message)
34
+ end
35
+
36
+ def example_failed(failure)
37
+ failure_output(failure.example)
38
+ end
39
+
40
+ private
41
+
42
+ def passed_output(example)
43
+ output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("#{current_indentation}#{example.description.strip}", :success)
44
+ format_output(example) if example.metadata.key?(:steps)
45
+ end
46
+
47
+ def pending_output(example, message)
48
+ output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} " \
49
+ "(PENDING: #{message})",
50
+ :pending)
51
+ end
52
+
53
+ def failure_output(example)
54
+ output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("#{current_indentation}#{example.description.strip} " \
55
+ "(FAILED - #{next_failure_index})",
56
+ :failure)
57
+ format_output(example) unless example.metadata[:steps].nil?
58
+ end
59
+
60
+ def next_failure_index
61
+ @next_failure_index ||= 0
62
+ @next_failure_index += 1
63
+ end
64
+
65
+ def current_indentation
66
+ ' ' * @group_level
67
+ end
68
+
69
+ def format_output(example)
70
+ example.metadata[:steps].each do |step|
71
+ output.puts RSpec::Core::Formatters::ConsoleCodes.wrap("#{' ' * (@group_level + 1)}step #{step[:index] + 1}: #{step[:step_name]}", current_color(step[:status]))
72
+ end
73
+ end
74
+
75
+ def current_color(status)
76
+ case status
77
+ when 'Pass' then :success
78
+ when 'Fail' then :failure
79
+ else :pending
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,139 @@
1
+ require 'rspec/core/formatters/base_formatter'
2
+
3
+ class ATMResultFormatter < RSpec::Core::Formatters::BaseFormatter
4
+ DEFAULT_RESULT_FORMATTER_OPTIONS = { run_only_found_tests: false, post_results: false }.freeze
5
+
6
+ RSpec::Core::Formatters.register self, :start, :example_started, :dump_summary, :close
7
+
8
+ def start(_notification)
9
+ @options = DEFAULT_RESULT_FORMATTER_OPTIONS.merge(ATMFormatter.config.result_formatter_options)
10
+ @client = ATM::Client.new(ATMFormatter.config.to_hash)
11
+ if @options[:run_only_found_tests]
12
+ test_run_data = @client.TestRun.find(ATMFormatter.config.test_run_id)
13
+ if test_run_data.code != 200
14
+ puts ATM::TestRunError.new(test_run_data).message
15
+ exit
16
+ end
17
+ @test_cases = @client.TestCase.retrive_based_on_username(test_run_data, ATMFormatter.config.username.downcase)
18
+ end
19
+
20
+ @time_stamp = "#{Time.now.to_i.to_s}-#{rand(10**10)}"
21
+ @test_results = {}
22
+ @test_data = []
23
+ Dir.mkdir('test_results') unless Dir.exist?('test_results')
24
+ end
25
+
26
+ def dump_summary(notification)
27
+ notification.examples.each do |example|
28
+ file_name = example.metadata[:file_path].match(/[^\/]*_spec/)[0] # "#{}.json"
29
+ file_path = "#{file_name}_#{@time_stamp}"
30
+ @test_results[file_path.to_sym] = { test_cases: [] }
31
+ test_data = @client.TestRun.process_result(process_metadata(example))
32
+ @test_data << if ATMFormatter.config.test_run_id
33
+ test_data.merge!(test_run_id: ATMFormatter.config.test_run_id, test_case: example.metadata[:test_id], file_path: file_path)
34
+ else
35
+ test_data.merge!(test_case: example.metadata[:test_id], file_path: file_path)
36
+ end
37
+ end
38
+
39
+ @test_results.each do |k, _v|
40
+ @test_data.each do |test_case_data|
41
+ if k.to_s == test_case_data[:file_path]
42
+ test_case_data.delete(:file_path)
43
+ @test_results[k][:test_cases] << test_case_data
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def close(_notification)
50
+ @test_results.each do |key, _value|
51
+ File.open("test_results/#{key}.json", 'w') do |config|
52
+ config.puts(JSON.pretty_generate(@test_results[key]))
53
+ end
54
+ end
55
+ end
56
+
57
+ def example_started(notification)
58
+ if notification.example.metadata[:environment] || ATMFormatter.config.environment
59
+ configure_env(notification.example)
60
+ end
61
+
62
+ if @options[:run_only_found_tests] && !@test_cases.include?(test_id(notification.example))
63
+ notification.example.metadata[:skip] = "#{notification.example.metadata[:test_id]} was not found in the #{ATMFormatter.config.test_run_id} test run."
64
+ end
65
+
66
+ notification.example.metadata[:step_index] = 0
67
+ end
68
+
69
+ private
70
+
71
+ def configure_env(example)
72
+ if (!example.metadata[:environment].nil? && !example.metadata[:environment].strip.empty?) &&
73
+ (!ATMFormatter.config.environment.nil? && !ATMFormatter.config.environment.strip.empty?)
74
+ warn("WARNING: Environment is set twice!
75
+ ATMFormatter.config.environment: #{ATMFormatter.config.environment}
76
+ Spec: #{example.metadata[:environment]}
77
+ Will use environment provided by the spec.")
78
+ elsif example.metadata[:environment].nil? || example.metadata[:environment].strip.empty?
79
+ example.metadata[:environment] = ATMFormatter.config.environment
80
+ end
81
+ end
82
+
83
+ def process_metadata(example)
84
+ {
85
+ test_case: test_id(example),
86
+ status: status(example.metadata[:execution_result]),
87
+ environment: fetch_environment(example),
88
+ comment: comment(example.metadata),
89
+ execution_time: run_time(example.metadata[:execution_result]),
90
+ script_results: steps(example.metadata)
91
+ }.delete_if { |_k, v| v.nil? }
92
+ end
93
+
94
+ def fetch_environment(example)
95
+ if example.metadata[:environment] && !example.metadata[:environment].strip.empty?
96
+ example.metadata[:environment]
97
+ elsif ATMFormatter.config.environment && !ATMFormatter.config.environment.strip.empty?
98
+ ATMFormatter.config.environment
99
+ end
100
+ end
101
+
102
+ def test_id(example)
103
+ example.metadata[:test_id]
104
+ end
105
+
106
+ def status(scenario)
107
+ status_code(scenario.status)
108
+ end
109
+
110
+ def comment(scenario)
111
+ comment = []
112
+ return if scenario[:kanoah_evidence].nil? &&
113
+ scenario[:execution_result].exception.inspect == 'nil'
114
+ comment << scenario[:execution_result].exception.inspect
115
+
116
+ comment << "#{scenario[:kanoah_evidence][:title]}<br />#{scenario[:kanoah_evidence][:path]}" unless scenario[:kanoah_evidence].nil?
117
+ comment.join('<br />')
118
+ end
119
+
120
+ def run_time(scenario)
121
+ scenario.run_time.to_i * 1000
122
+ end
123
+
124
+ def steps(scenario) # TODO: Make this better
125
+ return unless scenario[:steps]
126
+ arr = []
127
+ scenario[:steps].each { |s| arr << s.reject { |k, _v| k == :step_name } }
128
+ arr
129
+ end
130
+
131
+ def status_code(status)
132
+ case status
133
+ when :failed, :passed then
134
+ status.to_s.gsub('ed', '').capitalize
135
+ when :pending then
136
+ 'Not Supported'
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'atm_formatter/helpers/base_formatter'
2
+
3
+ class ATMUpdateTestFormatter < ATMFormatter::BaseFormatter
4
+ RSpec::Core::Formatters.register self, *NOTIFICATIONS
5
+
6
+ def example_started(notification)
7
+ if (notification.example.metadata.key?(:test_id) && notification.example.metadata[:test_id].strip.empty?) || !notification.example.metadata.key?(:test_id)
8
+ return
9
+ end
10
+
11
+ response = @client.TestCase.update(notification.example.metadata[:test_id], process_example(notification.example))
12
+ if response.code != 200
13
+ puts ATM::TestCaseError.new(response).message
14
+ exit
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ module ATMFormatter
2
+ class << self
3
+ attr_accessor :config
4
+ end
5
+
6
+ def self.configure
7
+ self.config ||= Configuration.new
8
+ yield(config)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :base_url, :test_run_id, :environment, :username, :password,
13
+ :project_id, :auth_type, :result_formatter_options, :create_test_formatter_options
14
+
15
+ def initialize
16
+ @base_url = nil
17
+ @test_run_id = nil
18
+ @project_id = nil
19
+ @environment = nil
20
+ @username = nil
21
+ @password = nil
22
+ @auth_type = nil
23
+ @result_formatter_options = nil
24
+ @create_test_formatter_options = nil
25
+ end
26
+
27
+ def to_hash
28
+ hash = {}
29
+ instance_variables.each { |var| hash[var.to_s.delete('@').to_sym] = instance_variable_get(var) }
30
+ hash
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atm_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.31
5
+ platform: ruby
6
+ authors:
7
+ - azohra
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: atm_ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-progressbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.8.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.8'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.8.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.14'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.14'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '12.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '12.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: coveralls
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.8.20
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.8.20
103
+ - !ruby/object:Gem::Dependency
104
+ name: pry
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.10.4
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.10.4
117
+ description: Write a longer description or delete this line.
118
+ email:
119
+ - ''
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".travis.yml"
127
+ - CODE_OF_CONDUCT.md
128
+ - Gemfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - atm_formatter.gemspec
133
+ - bin/console
134
+ - bin/setup
135
+ - lib/atm_create_test_formatter.rb
136
+ - lib/atm_formatter.rb
137
+ - lib/atm_formatter/adapter.rb
138
+ - lib/atm_formatter/example.rb
139
+ - lib/atm_formatter/helpers/base_formatter.rb
140
+ - lib/atm_formatter/steps.rb
141
+ - lib/atm_formatter/tasks/test_manipulation_tasks.rb
142
+ - lib/atm_formatter/version.rb
143
+ - lib/atm_output_formatter.rb
144
+ - lib/atm_result_formatter.rb
145
+ - lib/atm_update_test_formatter.rb
146
+ - lib/configuration.rb
147
+ homepage: https://github.com/azohra/atm_formatter
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.5.1
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Write a short summary, because Rubygems requires one.
171
+ test_files: []