Ruby_AppThwack 0.0.2

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: b71be676e1f46000b889e928f63334a86931a4b6
4
+ data.tar.gz: 67209b02a475f881edb3766ed9188e415a05e2e3
5
+ SHA512:
6
+ metadata.gz: 4ba2f44d203b363d38d2da96a33b3673164aa458c2f4258488656b11bdc69f2fa91a56f56afb8ba12237539e3af5b5743c2c998480049758407684c5b69e8fa1
7
+ data.tar.gz: 974e65fcf9d4e4ebc49f54cb90b849d9e396d49ae2fbc8532a7d87a53a547a227107c5db3c5c9ae5978df179c5d8925d9156edc8deee160af35b0eb462099c12
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Sam Stewart
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ ## Ruby AppThwack
2
+ Simple CLI for AppThwack.com's wonderful service.
3
+
4
+
5
+ ## To Do
6
+ 1. Cleanup options interface and move into configuration file
Binary file
data/bin/appthwack ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dotenv'
4
+ Dotenv.load
5
+
6
+ say_error 'Must set environment variable APPTHWACK_API_KEY' if ENV['APPTHWACK_API_KEY'].nil?
7
+
8
+ require 'commander/import'
9
+
10
+ $:.push File.expand_path("../../lib", __FILE__)
11
+ require 'ruby_appthwack'
12
+
13
+ HighLine.track_eof = false # Fix for built-in Ruby
14
+
15
+ program :version, AppThwack::VERSION
16
+ program :description, 'Run UI tests from the command-line on AppThwack.com'
17
+
18
+ program :help, 'Author', 'Sam Stewart <sam@playhaven.com>'
19
+ program :help, 'Website', 'http://playhaven.com'
20
+ program :help_formatter, :compact
21
+
22
+ default_command :help
23
+
24
+ require 'ruby_appthwack/commands'
@@ -0,0 +1,104 @@
1
+
2
+ require 'ostruct'
3
+ require "json"
4
+ require "typhoeus"
5
+ require "ostruct"
6
+
7
+ module AppThwack::API
8
+
9
+ class << self
10
+ def get_project_id(name)
11
+ res =
12
+ JSON.parse(
13
+ Typhoeus.get(
14
+ "https://appthwack.com/api/project/",
15
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:"
16
+ ).body
17
+ )
18
+
19
+ return (res.select { |project| project['name'].eql? name }).first['id']
20
+ end
21
+
22
+ def get_device_pool(proj_id, name)
23
+
24
+ res =
25
+ JSON.parse(
26
+ Typhoeus.get(
27
+ "https://appthwack.com/api/devicepool/#{proj_id}",
28
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:"
29
+ ).body
30
+ )
31
+
32
+ return (res.select { |pool| pool['name'].eql? name }).first['id']
33
+ end
34
+
35
+ def download_file(src, dst)
36
+
37
+ File.open(dst, 'w') { |f| f.write(Typhoeus.get(src).body) }
38
+
39
+ return dst
40
+ end
41
+
42
+ def upload_file(src)
43
+ f = Dir.glob( src ).first
44
+
45
+ res = JSON.parse(
46
+ Typhoeus.post(
47
+ "https://appthwack.com/api/file",
48
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
49
+ params: {
50
+ name: File.basename(f)
51
+ },
52
+ body: {
53
+ file: File.open(f,"r")
54
+ }
55
+ ).body
56
+ )
57
+
58
+ return { :file_id => res["file_id"], :succeeded? => res['message'].nil?, :message => res['message'] }
59
+ end
60
+
61
+ def start_test(name, proj_id, app_id, pool_id, params = {})
62
+
63
+ params.merge! project: proj_id, name: name, app: app_id, pool: pool_id
64
+
65
+ res = JSON.parse(
66
+ Typhoeus.post(
67
+ "https://appthwack.com/api/run",
68
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
69
+ params: params
70
+ ).body
71
+ )
72
+
73
+ return { :run_id => res['run_id'], :succeeded? => res['message'].nil?, :message => res['message'] }
74
+ end
75
+
76
+ def test_status?(proj_id, run_id)
77
+ res = JSON.parse(
78
+ Typhoeus.get(
79
+ "https://appthwack.com/api/run/#{proj_id}/#{run_id}/status",
80
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
81
+ ).body
82
+ )
83
+
84
+ return res['status']
85
+ end
86
+
87
+ def test_running?(proj_id, run_id)
88
+ return test_status?( proj_id, run_id ) != 'completed'
89
+ end
90
+
91
+ def download_results(proj_id, run_id)
92
+
93
+ resp = Typhoeus.get(
94
+ "https://appthwack.com/api/run/#{proj_id}/#{run_id}",
95
+ userpwd: "#{ENV['APPTHWACK_API_KEY']}:",
96
+ params: {
97
+ format: "archive"
98
+ }
99
+ )
100
+
101
+ return ( download_file resp.headers_hash['Location'], "#{proj_id}_#{run_id}.zip" ) if resp.code == 303
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,84 @@
1
+
2
+ command :run do |c|
3
+ c.syntax = 'appthwack run [options]'
4
+ c.summary = 'Packages tests and pushes them to AppThwack for Running'
5
+ c.description = ''
6
+
7
+ c.option '--platform PLATFORM', 'The platform of the application under test'
8
+ c.option '--project PROJECT', 'Name of AppThwack project'
9
+ c.option '--devices DEVICES', 'Name of device pool to use'
10
+ c.option '--testtype TYPE', 'Scheme used to build iOS app'
11
+ c.option '--app TEST', 'Path of the application (can be Glob syntax)'
12
+ c.option '--test TEST', 'Path of the test package'
13
+ c.option '--wait', 'Wait for the tests to complete'
14
+ c.option '--scheme SCHEME', 'XCode scheme for packaging the IPA'
15
+
16
+ c.action do |args, options|
17
+
18
+ options.proj_id = AppThwack::API.get_project_id options.project
19
+ options.pool_id = AppThwack::API.get_device_pool options.proj_id, options.devices
20
+
21
+ say_ok "Project ID: #{options.proj_id}"
22
+ say_ok "Pool ID: #{options.pool_id}"
23
+
24
+ # Feature: list of tests to include via command line?
25
+ if options.testtype.eql? 'calabash'
26
+ options.test = AppThwack::Packaging.create_calabash_package options.proj_id, options.test
27
+ end
28
+
29
+ # if the platform is iOS, make an IPA before building
30
+ if options.platform.eql? 'ios'
31
+ options.app = AppThwack::Packaging.create_ipa(options.scheme)
32
+ end
33
+
34
+ # start by uploading the app
35
+ options.app_id = (AppThwack::API.upload_file options.app)[:file_id]
36
+ say_ok "App package ID: #{options.app_id}"
37
+
38
+ exit 3 if options.app_id.nil?
39
+
40
+ # now upload the test package
41
+ options.test_id = (AppThwack::API.upload_file options.test)[:file_id]
42
+
43
+ say_ok "Test packagae ID: #{options.test_id}"
44
+
45
+ exit 4 if options.test_id.nil?
46
+
47
+ params = {}
48
+
49
+ params['calabash'] = { calabash: options.test_id }
50
+
51
+ params['junit'] = { junit: options.test_id }
52
+
53
+ result = AppThwack::API.start_test(
54
+ File.basename(Dir.glob(options.app).first),
55
+ options.proj_id,
56
+ options.app_id,
57
+ options.pool_id,
58
+ params[options.testtype]
59
+ )
60
+
61
+ options.run_id = result[:run_id]
62
+
63
+ say_ok "Run ID: #{options.run_id} with message: #{result[:message]}"
64
+
65
+ exit 5 if options.run_id.nil?
66
+
67
+ sleep 5
68
+
69
+ # wait for test to terminate
70
+ until not AppThwack::API.test_running? options.proj_id, options.run_id or not options.wait
71
+ print "."
72
+ sleep 30
73
+ end
74
+
75
+ # download the results
76
+ if options.download_results
77
+ zip = AppThwack::API.download_results proj_id, run_id
78
+ say_ok "Results zip #{zip}"
79
+ end
80
+
81
+ say_ok "Tests started successfully"
82
+
83
+ end
84
+ end
@@ -0,0 +1,15 @@
1
+ command :status do |c|
2
+ c.syntax = 'appthwack status [arguments]'
3
+ c.summary = 'Check on the status of a running test'
4
+ c.description = ''
5
+
6
+ c.option '--project PROJECT', 'The project name of the running tests'
7
+ c.option '--runid INT', 'The run ID of the test'
8
+
9
+
10
+ c.action do |args, options|
11
+ say_error 'Need project and run ID' if options.runid.nil? or options.project.nil?
12
+
13
+ puts AppThwack::API.test_status? AppThwack::API.get_project_id(options.project), options.runid
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ $:.push File.expand_path('../', __FILE__)
2
+
3
+ require 'commands/status'
4
+ require 'commands/run'
@@ -0,0 +1,31 @@
1
+
2
+ module AppThwack::Packaging
3
+
4
+ class << self
5
+ def create_ipa(scheme)
6
+ #uses Shenzhen gem
7
+ abort unless system "ipa build --scheme #{scheme} --configuration Release --no-archive"
8
+
9
+ return Dir.glob('*.ipa').first
10
+ end
11
+
12
+ def create_calabash_package proj_id, src, opts = {}
13
+ o = { :include_tests=> ["*.feature"], :exclude_tests=> nil}.merge opts
14
+
15
+ # create the archive if it doesn't already exist
16
+ unless File.extname(src) == '.zip'
17
+ # delete any old archives we have laying about
18
+ File.delete(src + '.zip') if File.exists?(src + '.zip')
19
+
20
+ included = (o[:include_tests].map { |t| "'#{src}/#{t}'"}).join(' ')
21
+ excluded = if o[:exclude_tests]; "-x #{ (o[:exclude_tests].map { |t| "'#{calabash}/#{t}'"}).join(' ') }" else "" end
22
+
23
+ `zip #{src}.zip #{src} . -r #{excluded} -i '#{src}/support/*' '#{src}/step_definitions/*' #{included}`
24
+ end
25
+
26
+ src << '.zip'
27
+
28
+ return src
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ module AppThwack
2
+ VERSION = '0.0.2'
3
+ end
4
+
5
+ require 'ruby_appthwack/appthwack_api.rb'
6
+ require 'ruby_appthwack/packaging.rb'
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby_appthwack"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "Ruby_AppThwack"
7
+ s.authors = ["Sam Stewart"]
8
+ s.email = "sam@playhaven.com"
9
+ s.homepage = "https://github.com/samstewart/ruby_appthwack"
10
+ s.version = AppThwack::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.summary = "Ruby AppThwack"
13
+ s.description = "CLI for running UI tests on AppThwack.com"
14
+
15
+ s.add_dependency "commander", "~> 4.1"
16
+ s.add_dependency "json", "~> 1.8"
17
+ s.add_dependency "faraday", "~> 0.8"
18
+ s.add_dependency "faraday_middleware", "~> 0.9"
19
+ s.add_dependency "dotenv", "~> 0.7"
20
+ s.add_dependency "shenzhen", "~> 0.4.0"
21
+
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "rake"
24
+
25
+ s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Ruby_AppThwack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sam Stewart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: shenzhen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: CLI for running UI tests on AppThwack.com
126
+ email: sam@playhaven.com
127
+ executables:
128
+ - appthwack
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ./lib/ruby_appthwack/appthwack_api.rb
133
+ - ./lib/ruby_appthwack/commands/run.rb
134
+ - ./lib/ruby_appthwack/commands/status.rb
135
+ - ./lib/ruby_appthwack/commands.rb
136
+ - ./lib/ruby_appthwack/packaging.rb
137
+ - ./lib/ruby_appthwack.rb
138
+ - ./LICENSE
139
+ - ./README.md
140
+ - ./Ruby_AppThwack-0.0.1.gem
141
+ - ./ruby_appthwack.gemspec
142
+ - bin/appthwack
143
+ homepage: https://github.com/samstewart/ruby_appthwack
144
+ licenses: []
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.0.0
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Ruby AppThwack
166
+ test_files: []