infrataster 0.1.2 → 0.1.3

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: 2c688ef83410f30dc9e25254d43f69a64ac91800
4
- data.tar.gz: edf44d55e56d2d2b146e42a4a1e971bd94e34f92
3
+ metadata.gz: 8ce1087098d32e5590380749af3c3d864cb877ff
4
+ data.tar.gz: 3db9a8a5b018a199ce49a90853b0906c820d22fb
5
5
  SHA512:
6
- metadata.gz: 59d06ca182ed05759cac708bf4c320b5df020cb10018b56f68751e0a719b0490b8c0219eb6f069dfd3db3a6faaa50b8aa54edbb73f279815ddd82fd9d03efa32
7
- data.tar.gz: 0dfd6f925864f1add5905ee34ff1fa6ff9fe4012e6a1d13e80814e87b9c840f161ce6224ab96d03ea52dc3d5ef0c641fe4871d16f7d9138ffdc723807677ef1f
6
+ metadata.gz: 6d03e0bee9d2b39ffaaf1f628c541532702aafe38771f4dc870125cc1e647d20cb1650fbbe9598fb31c5473b6208e26f5e97bf2d180424dc42a070be6f4480d5
7
+ data.tar.gz: 50e50689ea235aafbf3aa1729716e7996021310e532bf539be391bdc9a8958cfb73bc813e5e0e5a9994172d3d3ec4c648402d4f6a1a6320d720a2907627612f8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Infrataster Changelog
2
2
 
3
+ ## v0.1.3
4
+
5
+ * Don't create multiple phantomjs and browsermob proxy. `capybara` resources become faster.
6
+
3
7
  ## v0.1.2
4
8
 
5
9
  * Use poltergeist (PhantomJS) as capybara driver instead of selenium-webdriver.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Infrataster
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/infrataster.png)](http://badge.fury.io/rb/infrataster)
4
+
3
5
  Infrastructure Behavior Testing Framework.
4
6
 
5
7
  ## Usage
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "open-uri"
3
4
 
4
- def red(str)
5
- "\e[31m#{str}\e[m"
5
+ def yellow(str)
6
+ "\e[33m#{str}\e[m"
6
7
  end
7
8
 
8
9
  ENV['VAGRANT_CWD'] = File.expand_path('spec/integration/vm')
@@ -18,16 +19,23 @@ namespace :spec do
18
19
 
19
20
  namespace :integration do
20
21
  integration_dir = 'spec/integration'
22
+
21
23
  task :prepare => ['download_browsermob', 'start_vm'] do
22
24
  end
23
25
 
24
26
  task :download_browsermob do
25
27
  dir = File.join(integration_dir, 'vm/vendor/browsermob')
26
28
  unless Dir.exist?(dir)
27
- puts red("Downloading browsermob...")
29
+ puts yellow("Downloading browsermob...")
28
30
  Dir.mktmpdir do |tmp|
29
- cmd = "cd #{tmp} && wget -O browsermob-proxy.zip https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-9-bin.zip && unzip browsermob-proxy.zip"
30
- system cmd
31
+ open('https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-9-bin.zip') do |remote|
32
+ open(File.join(tmp, 'browsermob-proxy.zip'), 'wb') do |f|
33
+ f.write(remote.read)
34
+ end
35
+ end
36
+ Dir.chdir(tmp) do
37
+ system "unzip browsermob-proxy.zip"
38
+ end
31
39
  FileUtils.mv(File.join(tmp, 'browsermob-proxy-2.0-beta-9'), dir)
32
40
  end
33
41
  end
@@ -37,15 +45,15 @@ namespace :spec do
37
45
  dir = File.join(integration_dir, 'vm/vendor/cookbooks')
38
46
  # Berkshelf
39
47
  if Dir.exist?(dir)
40
- puts red("'#{dir}' already exists. If you want update cookbooks, delete the directory and re-run rake command")
48
+ puts yellow("'#{dir}' already exists. If you want update cookbooks, delete the directory and re-run rake command")
41
49
  else
42
- puts red('Installing cookbooks by berkshelf...')
43
- system "cd #{integartion_dir} && berks vendor vendor/cookbooks"
50
+ puts yellow('Installing cookbooks by berkshelf...')
51
+ system "cd #{integration_dir}/vm && berks vendor vendor/cookbooks"
44
52
  end
45
53
  end
46
54
 
47
55
  task :start_vm => ['berks_vendor'] do
48
- puts red('Starting VM...')
56
+ puts yellow('Starting VM...')
49
57
  system '/usr/bin/vagrant up'
50
58
  end
51
59
  end
@@ -7,6 +7,10 @@ module Infrataster
7
7
  @server ||= start_server
8
8
  end
9
9
 
10
+ def proxy
11
+ @proxy ||= server.create_proxy
12
+ end
13
+
10
14
  def bin_path
11
15
  @bin_path
12
16
  end
@@ -29,3 +33,4 @@ module Infrataster
29
33
  end
30
34
  end
31
35
  end
36
+
@@ -5,18 +5,29 @@ require 'capybara/poltergeist'
5
5
  module Infrataster
6
6
  module Contexts
7
7
  class CapybaraContext < BaseContext
8
+ def self.session
9
+ @session ||= prepare_session
10
+ end
11
+
12
+ def self.prepare_session
13
+ capybara_driver_name = :infrataster_driver
14
+
15
+ proxy = BrowsermobProxy.proxy
16
+ Capybara.register_driver capybara_driver_name do |app|
17
+ Capybara::Poltergeist::Driver.new(
18
+ app,
19
+ phantomjs_options: ["--proxy=http://#{proxy.host}:#{proxy.port}"],
20
+ )
21
+ end
22
+ Capybara::Session.new(capybara_driver_name)
23
+ end
24
+
8
25
  def initialize(*args)
9
26
  super(*args)
10
-
11
- register_capybara_driver
12
27
  end
13
28
 
14
29
  def session
15
- return @session if @session
16
-
17
- address, port, @gateway_finalize_proc = server.from_gateway_open(resource.uri.port)
18
- Capybara.app_host = "http://#{address}:#{port}"
19
- @session = Capybara::Session.new(capybara_driver_name)
30
+ self.class.session
20
31
  end
21
32
 
22
33
  def page
@@ -25,6 +36,12 @@ module Infrataster
25
36
 
26
37
  def before_each(example)
27
38
  example.example_group_instance.extend(Capybara::RSpecMatchers)
39
+
40
+ proxy = BrowsermobProxy.proxy
41
+ proxy.header({"Host" => resource.uri.host})
42
+
43
+ address, port, @gateway_finalize_proc = server.from_gateway_open(resource.uri.port)
44
+ Capybara.app_host = "http://#{address}:#{port}"
28
45
  end
29
46
 
30
47
  def after_each(example)
@@ -34,23 +51,6 @@ module Infrataster
34
51
  def method_missing(method, *args)
35
52
  session.public_send(method, *args)
36
53
  end
37
-
38
- private
39
- def register_capybara_driver
40
- proxy = BrowsermobProxy.server.create_proxy
41
- proxy.header({"Host" => resource.uri.host})
42
-
43
- Capybara.register_driver capybara_driver_name do |app|
44
- Capybara::Poltergeist::Driver.new(
45
- app,
46
- phantomjs_options: ["--proxy=http://#{proxy.host}:#{proxy.port}"],
47
- )
48
- end
49
- end
50
-
51
- def capybara_driver_name
52
- :"selenium_via_proxy_#{hash}"
53
- end
54
54
  end
55
55
  end
56
56
  end
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infrataster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec