shoot 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481486a2446a53d6b2bde074a155edbaa2b56e81
4
- data.tar.gz: f77ab42fb88e621cf40af833d46f56a65a8f382c
3
+ metadata.gz: aeabb7d1b0a3c562b69bd4176f58fd70efce1f73
4
+ data.tar.gz: 0826500463dd17d0d1d6258e6bccc728a4db32c0
5
5
  SHA512:
6
- metadata.gz: b9dd3b4c732bc39c04b2766a1103bee644396c618ad6233f91effebf719420b37b67ddf45b52117c7dd688b296978e38b0887727f6b883d96955cf62ec5b2d2c
7
- data.tar.gz: f19d120611d6220a4f845449a95c2f7830b9ac21ce5ec52a2675a1ce4aed9ee185ada5cf665d8d1715b956afeb4fbb221c04cf4dd17a9750a0bd2e4c0c2faf75
6
+ metadata.gz: e280c175e5cd57471645f856b68ca74c0d76551edd530d6b4918e9b10c1badd7a355a1fbdacb3b3b3ec4e492d65db6b34ae5f6ac03b0e7ea6c09d34ffa9b2414
7
+ data.tar.gz: 44fc47dbf6035f462b66f8d20cf47760ffaec6eeff791f0a60b814b431850b277baece61c99c754d96c3625b1a5f1977c9461a51eba02e739ee9daf1482edd84
data/README.md CHANGED
@@ -67,6 +67,16 @@ This will run all the methods of MyScenario and generate screenshots for all act
67
67
 
68
68
  The resulting images will be saved on <font size="7"> `.screenshots`</font> folder.
69
69
 
70
+ If you wanna just test your scenarios, without paying SauceLabs and wasting time with remote connections:
71
+
72
+ $ shoot test my_scenario.rb
73
+
74
+ Or you can run a whole folder, like:
75
+
76
+ $ shoot test my_scenarios/
77
+
78
+ The `test` command will run locally using phantomjs (capybara).
79
+
70
80
  You can choose to deactivate the browsers you don't wanna use, based on id as well. Example:
71
81
 
72
82
  $ shoot deactivate 2
@@ -77,6 +87,10 @@ If you want to deactivate all the active browsers at once you can run:
77
87
 
78
88
  $ shoot deactivate_all
79
89
 
90
+ To open all screenshots (on a Mac), run:
91
+
92
+ $ shoot open
93
+
80
94
 
81
95
  ## Contributing
82
96
 
data/lib/shoot/cli.rb CHANGED
@@ -7,6 +7,17 @@ module Shoot
7
7
  require 'fileutils'
8
8
  FileUtils::mkdir_p '.screenshots'
9
9
  BROWSERS_PATH = '.screenshots/.browsers.json'
10
+ map %w[--version -v] => :version
11
+
12
+ desc 'version, --version, -v', 'Shoot version'
13
+ def version
14
+ puts Shoot::VERSION
15
+ end
16
+
17
+ desc 'open', 'Opens all screenshots taken'
18
+ def open
19
+ open_all_screenshots
20
+ end
10
21
 
11
22
  desc 'list', 'List all platforms. Optionally pass a filter (e.g. browserstack list ie)'
12
23
  def list(filter = nil)
@@ -19,19 +30,15 @@ module Shoot
19
30
  end
20
31
 
21
32
  desc 'scenario', 'Runs the given scenario on all active platforms or one platform, based on ID'
22
- def scenario(file, id = nil, test = 'all')
23
- require_file(file)
24
- klass_name = File.basename(file, '.rb').split('_').map(&:capitalize).join
25
- klass = Kernel.const_get(klass_name)
26
-
33
+ def scenario(file, id = nil)
27
34
  runners = id ? [json[id.to_i]] : _active
28
- runners.each do |config|
29
- instance = klass.new(config)
30
- klass.instance_methods(false).each do |method|
31
- instance.shoot(method)
32
- end
33
- instance.ok
34
- end
35
+ runners.each {|config| run file, config }
36
+ end
37
+
38
+ desc 'test', 'Runs the given scenario or all files in a directory on a local phantomjs'
39
+ def test(path)
40
+ files = File.directory?(path) ? Dir.glob("#{path}/*.rb") : [path]
41
+ files.each{|file| run file }
35
42
  end
36
43
 
37
44
  desc 'activate', 'Activate one platform, based on ID or interval'
@@ -58,10 +65,33 @@ module Shoot
58
65
  end
59
66
 
60
67
  no_commands do
68
+ def open_all_screenshots
69
+ `open .screenshots/*.png`
70
+ end
71
+
72
+ def run(file, config=nil)
73
+ klass = get_const_from_file(file)
74
+ instance = klass.new(config)
75
+ klass.instance_methods(false).each do |method|
76
+ instance.shoot(method)
77
+ end
78
+ instance.ok
79
+ end
80
+
61
81
  def require_file(file)
62
82
  require Dir.pwd + '/' + file
63
83
  end
64
84
 
85
+ def constantize_file_name(file)
86
+ klass_name = File.basename(file, '.rb').split('_').map(&:capitalize).join
87
+ Kernel.const_get(klass_name)
88
+ end
89
+
90
+ def get_const_from_file(file)
91
+ require_file(file)
92
+ constantize_file_name(file)
93
+ end
94
+
65
95
  def table(browsers)
66
96
  table = browsers.map do |p|
67
97
  to_row(p)
@@ -1,6 +1,5 @@
1
1
  require 'selenium-webdriver'
2
2
  require 'capybara'
3
-
4
3
  class Shoot::Scenario
5
4
  URL = sprintf 'http://%s:%s@hub.browserstack.com/wd/hub',
6
5
  ENV['BROWSERSTACK_USER'],
@@ -8,15 +7,22 @@ class Shoot::Scenario
8
7
 
9
8
  include Capybara::DSL
10
9
 
11
- def initialize(platform)
12
- @platform = platform
13
- config_capabilities
10
+ def initialize(platform=nil)
11
+ if platform
12
+ @platform = platform
13
+ config_capabilities
14
+
15
+ Capybara.register_driver platform_name do |app|
16
+ Capybara::Selenium::Driver.new(app,
17
+ browser: :remote,
18
+ url: URL,
19
+ desired_capabilities: @capabilities)
20
+ end
21
+ else
22
+ require 'capybara/poltergeist'
14
23
 
15
- Capybara.register_driver platform_name do |app|
16
- Capybara::Selenium::Driver.new(app,
17
- browser: :remote,
18
- url: URL,
19
- desired_capabilities: @capabilities)
24
+ Capybara.run_server = false
25
+ @platform_name = :poltergeist
20
26
  end
21
27
 
22
28
  puts "Running #{platform_name}"
@@ -29,6 +35,9 @@ class Shoot::Scenario
29
35
  require 'fileutils'
30
36
  FileUtils::mkdir_p '.screenshots'
31
37
  save_screenshot(".screenshots/#{method} #{platform_name}.png")
38
+ rescue => e
39
+ puts "FAILED #{method}: #{e.inspect}"
40
+ save_screenshot(".screenshots/failed #{method} #{platform_name}.png")
32
41
  end
33
42
 
34
43
  def ok
data/lib/shoot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shoot
2
- VERSION = "0.2.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/shoot.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Shoot
2
2
  autoload :CLI, "shoot/cli"
3
3
  autoload :Scenario, "shoot/scenario"
4
- autoload :Version, "shoot/version"
4
+ autoload :VERSION, "shoot/version"
5
5
  end
data/shoot.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "shoot/version"
4
+ require "shoot"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "shoot"
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "thor", "~> 0.19"
28
28
  spec.add_dependency "colorize", "~> 0.7"
29
29
  spec.add_dependency "rest-client", "~> 1.7"
30
+ spec.add_dependency "poltergeist", "~> 1.6"
30
31
  end
data/spec/cli_spec.rb CHANGED
@@ -82,6 +82,45 @@ describe 'Shoot::CLI' do
82
82
  end
83
83
 
84
84
  describe 'scenario' do
85
+ before do
86
+ allow(cli).to receive(:_active).and_return(["foo"])
87
+ allow(cli).to receive(:run)
88
+ end
89
+
90
+ it 'runs scenario' do
91
+ cli.scenario('foo.rb')
92
+ expect(cli).to have_received(:run)
93
+ end
94
+ end
95
+
96
+ describe 'test' do
97
+ describe 'file' do
98
+ before do
99
+ allow(cli).to receive(:run)
100
+ end
101
+
102
+ it 'runs scenario' do
103
+ cli.test('foo.rb')
104
+ expect(cli).to have_received(:run).with("foo.rb")
105
+ end
106
+ end
107
+
108
+ describe 'directory' do
109
+ before do
110
+ allow(File).to receive(:directory?).with('foo').and_return(true)
111
+ allow(Dir).to receive(:glob).with('foo/*.rb').and_return(["foo/bar.rb", "foo/baz.rb"])
112
+ allow(cli).to receive(:run)
113
+ end
114
+
115
+ it 'runs scenario' do
116
+ cli.test('foo')
117
+ expect(cli).to have_received(:run).with("foo/bar.rb")
118
+ expect(cli).to have_received(:run).with("foo/baz.rb")
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'run' do
85
124
  before do
86
125
  class Foo
87
126
  def initialize(config); end
@@ -91,13 +130,11 @@ describe 'Shoot::CLI' do
91
130
  allow_any_instance_of(Foo).to receive(:shoot)
92
131
  expect_any_instance_of(Foo).to receive(:ok)
93
132
 
94
- allow(cli).to receive(:_active).and_return(["foo"])
95
- allow(cli).to receive(:require_file)
133
+ allow(cli).to receive(:get_const_from_file).with("foo.rb").and_return(Foo)
96
134
  end
97
135
 
98
136
  it 'runs scenario' do
99
- cli.scenario('foo.rb')
100
- expect(cli).to have_received(:require_file)
137
+ cli.run('foo.rb', foo: :bar)
101
138
  end
102
139
  end
103
140
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Lulkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: poltergeist
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.6'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.6'
125
139
  description: A helper to take shots on BrowserStack. Run the shoot binary for more
126
140
  info.
127
141
  email: