chemistrykit 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ #2.0.0 (2013-06-27)
2
+ - Updated to Selenium-Connect version to 2.0.0
3
+ - Improved performance with driver hooks
4
+ - Added the ability to specify config files on brew.
5
+ - Added the "catalyst" concept for injecting data into formulas.
6
+
1
7
  #1.3.0 (2013-06-22)
2
8
  - Added explicit recursive file loading process for formulas
3
9
  - Cleaned up documentation
data/chemistrykit.gemspec CHANGED
@@ -1,15 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "chemistrykit"
3
- s.version = "1.3.0"
3
+ s.version = "2.0.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Dave Haeffner", "Jason Fox"]
6
6
  s.email = ["dave@arrgyle.com", "jason@arrgyle.com"]
7
7
  s.homepage = "https://github.com/arrgyle/chemistrykit"
8
8
  s.summary = "A simple and opinionated web testing framework for Selenium that follows convention over configuration."
9
- s.description = "Updated file loading, documentation and tests."
9
+ s.description = "Added catalyst data injection, multiple configuration usage, improved perfomrance."
10
10
  s.license = 'MIT'
11
11
 
12
12
  s.files = `git ls-files`.split($/)
13
+ s.files.reject! { |file| file.include? '.jar' }
13
14
  s.test_files = s.files.grep(%r{^(scripts|spec|features)/})
14
15
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
16
  s.require_paths = ["lib"]
@@ -21,7 +22,7 @@ Gem::Specification.new do |s|
21
22
  s.add_dependency "selenium-webdriver", "~> 2.29.0"
22
23
  s.add_dependency "ci_reporter", "~> 1.8.3"
23
24
  s.add_dependency "rest-client", "~> 1.6.7"
24
- s.add_dependency "selenium-connect", "~> 1.9.3"
25
+ s.add_dependency "selenium-connect", "~> 2.0.0"
25
26
 
26
27
  s.add_development_dependency "rspec", "~> 2.12.0"
27
28
  s.add_development_dependency "aruba", "~> 0.5.1"
@@ -12,11 +12,7 @@ Feature: Brewing a ChemistryKit project
12
12
  And a file named "formulas/bookie.rb" with:
13
13
  """
14
14
  module Formulas
15
- class Bookie
16
- def initialize(driver)
17
- @driver = driver
18
- end
19
-
15
+ class Bookie < Formula
20
16
  def open(url)
21
17
  @driver.get url
22
18
  end
@@ -34,13 +30,12 @@ Feature: Brewing a ChemistryKit project
34
30
  end
35
31
  """
36
32
 
37
- Scenario Outline: Run All Configurations
38
- When I overwrite _config.yaml with:
33
+ Scenario: Localhost
34
+ Given a file named "config.yaml" with:
39
35
  """
36
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
40
37
  log: 'evidence'
41
- host: '<%= <hostname> %>'
42
- sauce_username: 'testing_arrgyle'
43
- sauce_api_key: 'ab7a6e17-16df-42d2-9ef6-c8d2539cc38a'
38
+ host: 'localhost'
44
39
  """
45
40
  When I run `ckit brew`
46
41
  Then the stdout should contain "1 example, 0 failures"
@@ -48,9 +43,18 @@ Feature: Brewing a ChemistryKit project
48
43
  | evidence/SPEC-Bookie.xml |
49
44
  | evidence/server.log |
50
45
 
51
- Examples:
52
- | hostname |
53
- | "localhost" |
54
- # | "saucelabs" |
55
-
56
46
 
47
+ Scenario: Saucelabs
48
+ Given a file named "config.yaml" with:
49
+ """
50
+ log: 'evidence'
51
+ host: 'saucelabs'
52
+ brower: 'iexplore'
53
+ os: 'windows 2003'
54
+ sauce_username: 'dave_arrgyle'
55
+ sauce_api_key: '58092e14-4e9c-4911-bfc4-a09ecc02db63'
56
+ browser_version: '8'
57
+ description: 'ckit feature check'
58
+ """
59
+ When I run `ckit brew`
60
+ Then the stdout should contain "1 example, 0 failures"
@@ -0,0 +1,88 @@
1
+ Feature: Catalyst
2
+ Catalyst: n. A pocket of data (consumed from a CSV file) used to drive a test that needs it.
3
+
4
+ Scenario: Use a catalyst value to drive a test
5
+ Given I run `ckit new catalyst-example`
6
+ And I cd to "catalyst-example"
7
+
8
+ And a file named "formulas/lib/catalysts/google_test_data.csv" with:
9
+ """
10
+ url,http://www.google.com
11
+ search_query,Flying Elephants
12
+ """
13
+
14
+ And a file named "formulas/google.rb" with:
15
+ """
16
+ module Formulas
17
+ class Google < Formula
18
+
19
+ def visit
20
+ open catalyst.url
21
+ end
22
+
23
+ def search
24
+ search_box = find id: 'gbqfq'
25
+ search_box.send_keys catalyst.search_query
26
+ search_box.send_keys :enter
27
+ end
28
+
29
+ def search_results_found?
30
+ wait_for(5) { displayed? id: 'search' }
31
+ search_results = find id: 'search'
32
+ search_results.text.include?(catalyst.search_query)
33
+ end
34
+
35
+ end
36
+ end
37
+ """
38
+
39
+ And a file named "formulas/lib/formula.rb" with:
40
+ """
41
+ module Formulas
42
+ class Formula < ChemistryKit::Formula::Base
43
+
44
+ def open(url)
45
+ @driver.get url
46
+ end
47
+
48
+ def find(locator)
49
+ @driver.find_element locator
50
+ end
51
+
52
+ def displayed?(locator)
53
+ begin
54
+ find(locator).displayed?
55
+ rescue
56
+ false
57
+ end
58
+ end
59
+
60
+ def wait_for(seconds=2)
61
+ Selenium::WebDriver::Wait.new(:timeout => seconds).until { yield }
62
+ end
63
+ end
64
+ end
65
+ """
66
+
67
+ And a file named "beaker/google_beaker.rb" with:
68
+ """
69
+ describe "Google", :depth => 'shallow' do
70
+ let(:google) { Formulas::Google.new(@driver) }
71
+
72
+ it "loads an external web page" do
73
+ google.catalyze('formulas/lib/catalysts/google_test_data.csv')
74
+ google.visit
75
+ google.search
76
+ google.search_results_found?.should eq true
77
+ end
78
+ end
79
+ """
80
+
81
+ And a file named "config.yaml" with:
82
+ """
83
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
84
+ log: 'evidence'
85
+ host: 'localhost'
86
+ """
87
+ When I run `ckit brew`
88
+ Then the stdout should contain "1 example, 0 failures"
@@ -3,6 +3,12 @@ Feature: Exit Status
3
3
  Background:
4
4
  Given I run `ckit new cheese`
5
5
  And I cd to "cheese"
6
+ And a file named "config.yaml" with:
7
+ """
8
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
9
+ log: 'evidence'
10
+ host: 'localhost'
11
+ """
6
12
 
7
13
  Scenario: Passing
8
14
  And a file named "beaker/test_beaker.rb" with:
@@ -4,6 +4,12 @@ Formulas should be loaded in the correct order with thier dependencies
4
4
  Scenario: Load the libs first
5
5
  Given I run `ckit new big-project`
6
6
  And I cd to "big-project"
7
+ And a file named "config.yaml" with:
8
+ """
9
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
10
+ log: 'evidence'
11
+ host: 'localhost'
12
+ """
7
13
  And a file named "formulas/big.rb" with:
8
14
  """
9
15
  module Formulas
@@ -20,11 +26,7 @@ Formulas should be loaded in the correct order with thier dependencies
20
26
  And a file named "formulas/lib/formula.rb" with:
21
27
  """
22
28
  module Formulas
23
- class Formula
24
- def initialize(driver)
25
- @driver = driver
26
- end
27
-
29
+ class Formula < ChemistryKit::Formula::Base
28
30
  def helper_open(url)
29
31
  @driver.get url
30
32
  end
@@ -0,0 +1,55 @@
1
+ Feature: Support for multiple configuration files
2
+ In order to quickly change between different configurations
3
+ As a chemistry kit harness developer
4
+ I want to specify different configuration files on the command line
5
+
6
+ Background:
7
+ Given I run `ckit new config-test`
8
+ And I cd to "config-test"
9
+ And a file named "beaker/test_beaker.rb" with:
10
+ """
11
+ describe "Cheese", :depth => 'shallow' do
12
+ it "loads an external web page" do
13
+ @driver.get "http://www.google.com"
14
+ @driver.title.should include("Google")
15
+ end
16
+ end
17
+ """
18
+ Scenario: The default will be conifg.yaml
19
+ Given a directory named "evidence_config"
20
+ When I overwrite config.yaml with:
21
+ """
22
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
23
+ log: 'evidence_config'
24
+ host: 'localhost'
25
+ """
26
+ When I run `ckit brew`
27
+ Then the stdout should contain "1 example, 0 failures"
28
+ And the following files should exist:
29
+ | evidence_config/server.log |
30
+
31
+ Scenario: I can specifiy an alternative configuration with --config
32
+ Given a directory named "evidence_alternate"
33
+ And a file named "alternate.yaml" with:
34
+ """
35
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
36
+ log: 'evidence_alternate'
37
+ host: 'localhost'
38
+ """
39
+ When I run `ckit brew --config alternate.yaml`
40
+ Then the stdout should contain "1 example, 0 failures"
41
+ And the following files should exist:
42
+ | evidence_alternate/server.log |
43
+
44
+ Scenario: I can specifiy an alternative configuration with -c
45
+ Given a directory named "evidence_alternate"
46
+ And a file named "alternate.yaml" with:
47
+ """
48
+ jar: '../../../vendor/selenium-server-standalone-2.33.0.jar'
49
+ log: 'evidence_alternate'
50
+ host: 'localhost'
51
+ """
52
+ When I run `ckit brew -c alternate.yaml`
53
+ Then the stdout should contain "1 example, 0 failures"
54
+ And the following files should exist:
55
+ | evidence_alternate/server.log |
data/features/new.feature CHANGED
@@ -6,12 +6,14 @@ Feature: ckit new
6
6
  When I run `bundle exec ckit new new-project`
7
7
  And I cd to "new-project"
8
8
 
9
- @announce
10
9
  Scenario: Test Harness is created
11
10
  Then the following directories should exist:
12
- | beakers |
13
- | formulas |
14
- | evidence |
11
+ | beakers |
12
+ | formulas |
13
+ | formulas/lib |
14
+ | formulas/lib/catalysts |
15
+ | evidence |
15
16
  And the following files should exist:
16
- | _config.yaml |
17
- | .rspec |
17
+ | config.yaml |
18
+ | .rspec |
19
+ | formulas/lib/formula.rb |
@@ -4,3 +4,7 @@ Before do
4
4
  @aruba_timeout_seconds = 90
5
5
  @dirs = ["build/tmp"]
6
6
  end
7
+
8
+ After do
9
+ FileUtils.rm_rf("build/tmp")
10
+ end
@@ -0,0 +1,32 @@
1
+ require 'csv'
2
+
3
+ module ChemistryKit
4
+ class Catalyst
5
+ #this class serves as a standard container for data that can be injected into a formula
6
+
7
+ def initialize(data_file)
8
+ @data = {}
9
+ CSV.foreach(data_file) do | row |
10
+ @data[row[0].to_sym] = row[1]
11
+ end
12
+ end
13
+
14
+ def method_missing(name)
15
+ validate_key name
16
+ @data[name]
17
+ end
18
+
19
+ def get_value_for(key)
20
+ validate_key key
21
+ @data[key.to_sym]
22
+ end
23
+
24
+ private
25
+
26
+ def validate_key(key)
27
+ unless @data.has_key?(key.to_sym)
28
+ raise "Unknown \"#{key}\""
29
+ end
30
+ end
31
+ end
32
+ end
@@ -5,6 +5,8 @@ require 'chemistrykit/cli/new'
5
5
  require 'chemistrykit/cli/formula'
6
6
  require 'chemistrykit/cli/beaker'
7
7
  require 'chemistrykit/cli/helpers/formula_loader'
8
+ require 'chemistrykit/catalyst'
9
+ require 'chemistrykit/formula/base'
8
10
 
9
11
  module ChemistryKit
10
12
  module CLI
@@ -26,7 +28,9 @@ module ChemistryKit
26
28
  desc "brew", "Run ChemistryKit"
27
29
  method_option :params, :type => :hash
28
30
  method_option :tag, :default => ['depth:shallow'], :type => :array
31
+ method_option :config, :default => 'config.yaml', :aliases => "-c", :desc => "Supply alternative config file."
29
32
  def brew
33
+ load_config
30
34
  require 'chemistrykit/shared_context'
31
35
  pass_params if options['params']
32
36
  turn_stdout_stderr_on_off
@@ -58,6 +62,12 @@ module ChemistryKit
58
62
  ENV['CI_CAPTURE'] = 'on'
59
63
  end
60
64
 
65
+ def load_config
66
+ #not wild about using an env variable here... but maybe it makes sense
67
+ #just not sure how to inject it into the shared context.
68
+ ENV['CONFIG_FILE'] = options['config']
69
+ end
70
+
61
71
  def setup_tags
62
72
  @tags = {}
63
73
  options['tag'].each do |tag|
@@ -0,0 +1,21 @@
1
+ module ChemistryKit
2
+ module Formula
3
+ class Base
4
+
5
+ attr_accessor :catalyst
6
+
7
+ def initialize(driver)
8
+ @driver = driver
9
+ end
10
+
11
+ def catalyze(path_to_file)
12
+ self.catalyst = ChemistryKit::Catalyst.new(path_to_file)
13
+ end
14
+
15
+ def catalyst
16
+ @catalyst
17
+ end
18
+
19
+ end #Base
20
+ end #Formula
21
+ end #ChemistryKit
@@ -6,7 +6,7 @@ module ChemistryKit
6
6
  extend RSpec::Core::SharedContext
7
7
 
8
8
  SeleniumConnect.configure do |c|
9
- c.config_file = File.join(Dir.getwd, '_config.yaml')
9
+ c.config_file = File.join(Dir.getwd, ENV['CONFIG_FILE'])
10
10
  end
11
11
 
12
12
  before(:each) do
@@ -14,6 +14,10 @@ module ChemistryKit
14
14
  end
15
15
 
16
16
  after(:each) do
17
+ @driver.quit
18
+ end
19
+
20
+ after(:all) do
17
21
  SeleniumConnect.finish
18
22
  end
19
23
 
@@ -0,0 +1,4 @@
1
+ class Formula < ChemistryKit::Formula::Base
2
+ #this is where you can define generic helper functions that are inhereted by
3
+ #the rest of your formulas
4
+ end
@@ -1,9 +1,7 @@
1
1
  module Formulas
2
- class <%= name.capitalize %>
2
+ class <%= name.capitalize %> < Formula
3
+
3
4
 
4
- def initialize(driver)
5
- @driver = driver
6
- end
7
5
 
8
6
  end
9
7
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChemistryKit::Catalyst do
4
+
5
+ before(:each) do
6
+
7
+ Dir.mkdir(File.join(TEST_TMP_PATH, 'catalyst'))
8
+ @data_file = File.join(TEST_TMP_PATH, 'catalyst', 'catalyst_data.csv')
9
+ File.open(@data_file, 'w') {|f| f.write("first_key,first_value\nsecond_key,second_value") }
10
+ @catalyst = ChemistryKit::Catalyst.new(@data_file)
11
+ end
12
+
13
+ it 'Should take a csv file on initialization.' do
14
+ @catalyst.should be_an_instance_of ChemistryKit::Catalyst
15
+ end
16
+
17
+ it 'Should respond to a named key.' do
18
+ @catalyst.first_key.should be == 'first_value'
19
+ @catalyst.second_key.should be == 'second_value'
20
+ end
21
+
22
+ it 'Should respond to a convienence method.' do
23
+ @catalyst.get_value_for('second_key').should be == 'second_value'
24
+ @catalyst.get_value_for('first_key').should be == 'first_value'
25
+ end
26
+
27
+ it 'Should throw an exception for a non existant key.' do
28
+ expect {
29
+ @catalyst.get_value_for('third_key')
30
+ }.to raise_error("Unknown \"third_key\"")
31
+
32
+ expect {
33
+ @catalyst.third_key
34
+ }.to raise_error("Unknown \"third_key\"")
35
+
36
+ end
37
+
38
+ after(:each) do
39
+ FileUtils.rm_rf(File.join(TEST_TMP_PATH, 'catalyst'))
40
+ end
41
+
42
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChemistryKit::Formula::Base do
4
+
5
+ before(:each) do
6
+ #ideally we should mock the driver and not pass in nil
7
+ driver = nil
8
+ @formula_base = ChemistryKit::Formula::Base.new(driver)
9
+
10
+ Dir.mkdir(File.join(TEST_TMP_PATH, 'catalyst'))
11
+ @data_file = File.join(TEST_TMP_PATH, 'catalyst', 'catalyst_data.csv')
12
+ File.open(@data_file, 'w') {|f| f.write("first_key,first_value\nsecond_key,second_value") }
13
+ @catalyst = ChemistryKit::Catalyst.new(@data_file)
14
+ end
15
+
16
+ it 'Should allow a catalyst to be set.' do
17
+ @formula_base.catalyst = @catalyst
18
+ @formula_base.catalyst.should be_an_instance_of ChemistryKit::Catalyst
19
+ end
20
+
21
+ it 'Should allow the use of catalyze as a convenience method.' do
22
+ @formula_base.catalyze(@data_file)
23
+ @formula_base.catalyst.should be_an_instance_of ChemistryKit::Catalyst
24
+ end
25
+
26
+ after(:each) do
27
+ FileUtils.rm_rf(File.join(TEST_TMP_PATH, 'catalyst'))
28
+ end
29
+
30
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,8 @@ require 'bundler/setup'
10
10
  require 'fileutils'
11
11
  #not sure it this is the right way to include all the files under test.
12
12
  require_relative '../lib/chemistrykit/cli/helpers/formula_loader'
13
+ require_relative '../lib/chemistrykit/formula/base'
14
+ require_relative '../lib/chemistrykit/catalyst'
13
15
 
14
16
  TEST_TMP_PATH = File.join(Dir.pwd, 'build', 'tmp')
15
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chemistrykit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-22 00:00:00.000000000 Z
13
+ date: 2013-06-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -99,7 +99,7 @@ dependencies:
99
99
  requirements:
100
100
  - - ~>
101
101
  - !ruby/object:Gem::Version
102
- version: 1.9.3
102
+ version: 2.0.0
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
@@ -107,7 +107,7 @@ dependencies:
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: 1.9.3
110
+ version: 2.0.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -172,7 +172,8 @@ dependencies:
172
172
  - - ~>
173
173
  - !ruby/object:Gem::Version
174
174
  version: 10.0.3
175
- description: Updated file loading, documentation and tests.
175
+ description: Added catalyst data injection, multiple configuration usage, improved
176
+ perfomrance.
176
177
  email:
177
178
  - dave@arrgyle.com
178
179
  - jason@arrgyle.com
@@ -196,27 +197,35 @@ files:
196
197
  - chemistrykit.gemspec
197
198
  - ext/mkrf_conf.rb
198
199
  - features/brew.feature
200
+ - features/catalyst.feature
199
201
  - features/exit_status.feature
200
202
  - features/load_page_objects.feature
203
+ - features/multi-config.feature
201
204
  - features/new.feature
202
205
  - features/step_definitions/steps.rb
203
206
  - features/support/env.rb
204
207
  - lib/chemistrykit.rb
208
+ - lib/chemistrykit/catalyst.rb
205
209
  - lib/chemistrykit/cli/beaker.rb
206
210
  - lib/chemistrykit/cli/cli.rb
207
211
  - lib/chemistrykit/cli/formula.rb
208
212
  - lib/chemistrykit/cli/helpers/formula_loader.rb
209
213
  - lib/chemistrykit/cli/new.rb
214
+ - lib/chemistrykit/formula/base.rb
210
215
  - lib/chemistrykit/shared_context.rb
211
216
  - lib/templates/beaker.tt
212
217
  - lib/templates/beaker_with_formula.tt
213
218
  - lib/templates/chemistrykit/.rspec
214
- - lib/templates/chemistrykit/_config.yaml.tt
215
219
  - lib/templates/chemistrykit/beakers/.gitkeep
220
+ - lib/templates/chemistrykit/config.yaml.tt
216
221
  - lib/templates/chemistrykit/evidence/.gitkeep
217
222
  - lib/templates/chemistrykit/formulas/.gitkeep
223
+ - lib/templates/chemistrykit/formulas/lib/catalysts/.gitkeep
224
+ - lib/templates/chemistrykit/formulas/lib/formula.rb
218
225
  - lib/templates/formula.tt
226
+ - spec/chemistrykit/catalyst_spec.rb
219
227
  - spec/chemistrykit/cli/helpers/formula_loader_spec.rb
228
+ - spec/chemistrykit/formula/base_spec.rb
220
229
  - spec/spec_helper.rb
221
230
  homepage: https://github.com/arrgyle/chemistrykit
222
231
  licenses:
@@ -246,10 +255,14 @@ summary: A simple and opinionated web testing framework for Selenium that follow
246
255
  convention over configuration.
247
256
  test_files:
248
257
  - features/brew.feature
258
+ - features/catalyst.feature
249
259
  - features/exit_status.feature
250
260
  - features/load_page_objects.feature
261
+ - features/multi-config.feature
251
262
  - features/new.feature
252
263
  - features/step_definitions/steps.rb
253
264
  - features/support/env.rb
265
+ - spec/chemistrykit/catalyst_spec.rb
254
266
  - spec/chemistrykit/cli/helpers/formula_loader_spec.rb
267
+ - spec/chemistrykit/formula/base_spec.rb
255
268
  - spec/spec_helper.rb