results_keeper_rspec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ebfbea546c247c4e427782f1fa76643adbe7ebc
4
+ data.tar.gz: 616797e0680461ae6f96f6ec2623cbb1de26f6f6
5
+ SHA512:
6
+ metadata.gz: 2dd3b218f01b808b6443e6cc8ac63da8a89a47d66dcecfb26fd520f96a4c886aa0df0bb5a77ac0bf1a731cb62882b22ee26158f22c0c42d166f1be59fac3baaf
7
+ data.tar.gz: da447dc30810ba95d6ac58b077aeaff3a0b856e345a3bb0069129b4906960e07738eee17e76bbcc7974e924f5df4e208db87a171fc4633ab9e349e66bea7331d
@@ -0,0 +1,82 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'rest_client'
4
+ require_relative 'string'
5
+ require 'singleton'
6
+
7
+ class ResultsKeeperRspec
8
+ include Singleton
9
+
10
+ attr_reader :revision_name, :revision_project
11
+
12
+ DEFAULT_PORT = 80
13
+ DEFAULT_HOST = 'results-keeper.herokuapp.com'
14
+
15
+ def initialize
16
+ @revision_name = ENV['REVISION_NAME'] || "Result for #{Time.now}"
17
+ @revision_project = ENV['PROJECT_NAME'] || 'Default'
18
+ end
19
+
20
+ def send_revision
21
+ data = { revision: @revision_name, project: project_name }
22
+ @revision = send_json(data, 'revisions')
23
+ end
24
+
25
+ def send_revision_complete
26
+ data = { revision: @revision_name, project: project_name, completed: 1 }
27
+ send_json(data, 'revisions')
28
+ end
29
+
30
+ def send_test(scenario, screenshot_path=nil)
31
+ status = scenario.exception ? 'failed' : 'passed'
32
+ scenario_error = scenario.exception.message if scenario.exception
33
+ run_path = "rspec #{scenario.location}"
34
+ data = {
35
+ name: "#{scenario.example_group.description} - #{scenario.description}",
36
+ status: status,
37
+ feature_name: scenario.example_group.description,
38
+ run_path: run_path,
39
+ error: scenario_error,
40
+ revision_id: @revision['revision_id']
41
+ }
42
+ @test = send_json(data, 'tests')
43
+ send_screenshot(screenshot_path) if screenshot_path
44
+ end
45
+
46
+ def send_json(body, path)
47
+ @host = ENV['REPORT_SERVER_HOST'] || DEFAULT_HOST
48
+ @port = ENV['REPORT_SERVER_PORT'] || DEFAULT_PORT
49
+
50
+ body['secret_key'] = ENV['RK_SECRET_KEY']
51
+ @path = "/api/#{path}"
52
+ @body = body.to_json
53
+
54
+ request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' =>'application/json'})
55
+ request.body = @body
56
+ response = Net::HTTP.new(@host, @port).start {|http| http.request(request) }
57
+ puts " RK: #{response.code} - #{response.message}".blue
58
+ result_hash = JSON.parse(response.body) rescue console_message('There seems to be a problem. Are you authorized?')
59
+ result_hash
60
+ end
61
+
62
+ def send_screenshot(screenshot_path)
63
+ if ENV['SEND_SCREENSHOT']
64
+ t1 = Thread.new do
65
+ params = { project: @revision['project_id'], revision: @revision['revision_id'], test: @test['id'] }
66
+ RestClient.post("http://#{@host}:#{@port}/api/tests/upload_screenshot",
67
+ :name_of_file_param => File.new(screenshot_path), :body => params)
68
+ end
69
+ t1.join
70
+ File.delete(screenshot_path)
71
+ end
72
+ end
73
+
74
+ def project_name
75
+ ENV['PROJECT_NAME']
76
+ end
77
+
78
+ def console_message(text)
79
+ puts " RK: #{text}".blue
80
+ end
81
+ end
82
+
data/lib/string.rb ADDED
@@ -0,0 +1,21 @@
1
+ class String
2
+ def colorize(color_code)
3
+ "\e[#{color_code}m#{self}\e[0m"
4
+ end
5
+
6
+ def red
7
+ colorize(31)
8
+ end
9
+
10
+ def blue
11
+ colorize(96)
12
+ end
13
+
14
+ def green
15
+ colorize(92)
16
+ end
17
+
18
+ def yellow
19
+ colorize(33)
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: results_keeper_rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Kozakov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: flickraw
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Results Keeper is a application which can help you to track and manage
42
+ your Rspec test results using this gem as a client.
43
+ email: ivankozakov0@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/results_keeper_rspec.rb
49
+ - lib/string.rb
50
+ homepage: https://bitbucket.org/results_keeper/results_keeper_rspec/
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.4.8
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Result Keeper Gem For Rspec Tests
74
+ test_files: []