chemistrykit 3.8.0 → 3.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ #3.8.1 (2013-08-09)
2
+ Cleaned up chemists to use same instance in the formulas and bug fixes
3
+
4
+ - Bumped version to 3.8.1 to prepare for release.
5
+ - updated docs and moved the chemist aware module require to the base class
6
+ - updated tests and chemist to reflect the mutability of type but not key
7
+ - improved chemists by ensuring the same chemist object is always in play so that different formulas that update it state work together, also fixed a small bug with the loading of formulas by name
8
+
1
9
  #3.8.0 (2013-08-05)
2
10
  Implemented the chemists feature to add user data management as well as a simplified strategy for loading formulas
3
11
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- #ChemistryKit 3.8.0 (2013-08-05)
1
+ #ChemistryKit 3.8.1 (2013-08-09)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/chemistrykit.png)](http://badge.fury.io/rb/chemistrykit) [![Build Status](https://travis-ci.org/arrgyle/chemistrykit.png?branch=develop)](https://travis-ci.org/jrobertfox/chef-broiler-platter) [![Code Climate](https://codeclimate.com/github/arrgyle/chemistrykit.png)](https://codeclimate.com/github/arrgyle/chemistrykit) [![Coverage Status](https://coveralls.io/repos/arrgyle/chemistrykit/badge.png?branch=develop)](https://coveralls.io/r/arrgyle/chemistrykit?branch=develop)
4
4
 
@@ -114,8 +114,11 @@ module Formulas
114
114
  ...
115
115
  end
116
116
  end
117
+ ```
117
118
 
119
+ Note that because the `Chemist` is set after the instantiation of your formula by the `FormulaLab` you would *not be able* to do things in the constructor of your formula that depend on a chemist, unless you are explicitly passing in the `Chemist`. We suggest that you keep the instantiation of your page objects separate from the actions they take.
118
120
 
121
+ ```Ruby
119
122
  # my_beaker.rb
120
123
  describe "my beaker", :depth => 'shallow' do
121
124
  let(:my_formula) { @formula_lab.using('my_formula').with('admin1').mix }
@@ -131,7 +134,7 @@ Here is a summary of the other methods available:
131
134
  - `.with_random(type)` - Load a chemist at random from all those matching `type`
132
135
  - `.with_first(type)` - Load whatever chemist is first matched by `type`
133
136
 
134
- The FormulaLab will handle the heavy lifting of assembling your formal with a driver and correct user (if the formula needs one).
137
+ The FormulaLab will handle the heavy lifting of assembling your formula with a driver and correct chemist (if the formula needs one). Also note that the specific instance of chemist is cached so that any changes your formula makes to the chemist is reflected in other formulas that use it.
135
138
 
136
139
  ###Execution Order
137
140
  Chemistry Kit executes specs in a random order. This is intentional. Knowing the order a spec will be executed in allows for dependencies between them to creep in. Sometimes unintentionally. By having them go in a random order parallelization becomes a much easier.
data/chemistrykit.gemspec CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'chemistrykit'
5
- s.version = '3.8.0'
5
+ s.version = '3.8.1'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Dave Haeffner', 'Jason Fox']
8
8
  s.email = ['dave@arrgyle.com', 'jason@arrgyle.com']
9
9
  s.homepage = 'https://github.com/arrgyle/chemistrykit'
10
10
  s.summary = 'A simple and opinionated web testing framework for Selenium that follows convention over configuration.'
11
- s.description = 'Implemented the chemists feature to add user data management as well as a simplified strategy for loading formulas'
11
+ s.description = 'Cleaned up chemists to use same instance in the formulas and bug fixes'
12
12
  s.license = 'MIT'
13
13
 
14
14
  s.files = `git ls-files`.split($/)
@@ -23,8 +23,6 @@ Feature: Brewing a ChemistryKit project
23
23
  """
24
24
  And a file named "formulas/chemist_formula.rb" with:
25
25
  """
26
- require 'chemistrykit/formula/chemist_aware'
27
-
28
26
  module Formulas
29
27
  class ChemistFormula < Formula
30
28
  include ChemistryKit::Formula::ChemistAware
@@ -4,7 +4,8 @@ module ChemistryKit
4
4
  # representation of the user object for interacting with the system under test
5
5
  class Chemist
6
6
 
7
- attr_reader :key, :type, :data
7
+ attr_accessor :type
8
+ attr_reader :data, :key
8
9
 
9
10
  def initialize(key, type)
10
11
  @key = key.to_s
@@ -14,7 +15,7 @@ module ChemistryKit
14
15
 
15
16
  def data=(data)
16
17
  data.each do |key, value|
17
- send("#{key}=", value)
18
+ send("#{key}=", value) unless key == :key
18
19
  end
19
20
  end
20
21
 
@@ -13,6 +13,7 @@ module ChemistryKit
13
13
 
14
14
  def initialize(csv_path)
15
15
  @tables = []
16
+ @chemist_cache = {}
16
17
  files = csv_path.kind_of?(String) ? [csv_path] : csv_path
17
18
 
18
19
  files.each do |file|
@@ -32,7 +33,8 @@ module ChemistryKit
32
33
  def load_chemist_by_key(key)
33
34
  @tables.each do |table|
34
35
  chemist_data = table.find { |row| row[:key] == key }
35
- return make_chemist(key, chemist_data[:type], chemist_data) if chemist_data
36
+ chemist = make_chemist(key, chemist_data[:type], chemist_data) if chemist_data
37
+ return fetch_from_cache chemist
36
38
  end
37
39
  raise ArgumentError, "Chemist for type \"#{key}\" not found!"
38
40
  end
@@ -40,13 +42,13 @@ module ChemistryKit
40
42
  # Required Method
41
43
  # Load the first chemist found for a given type
42
44
  def load_first_chemist_of_type(type)
43
- load_chemists_of_type(type)[0]
45
+ fetch_from_cache(load_chemists_of_type(type)[0])
44
46
  end
45
47
 
46
48
  # Required Method
47
49
  # Loads a chemist at random from all those found with a given type
48
50
  def load_random_chemist_of_type(type)
49
- load_chemists_of_type(type).sample
51
+ fetch_from_cache(load_chemists_of_type(type).sample)
50
52
  end
51
53
 
52
54
  protected
@@ -73,6 +75,12 @@ module ChemistryKit
73
75
  chemist
74
76
  end
75
77
 
78
+ def fetch_from_cache(chemist)
79
+ return @chemist_cache[chemist.key.to_sym] if @chemist_cache.include?(chemist.key.to_sym)
80
+ @chemist_cache[chemist.key.to_sym] = chemist
81
+ fetch_from_cache chemist
82
+ end
83
+
76
84
  end
77
85
  end
78
86
  end
@@ -1,5 +1,7 @@
1
1
  # Encoding: utf-8
2
2
 
3
+ require 'chemistrykit/formula/chemist_aware'
4
+
3
5
  module ChemistryKit
4
6
  module Formula
5
7
  # Base functionality for the Formula class
@@ -53,7 +53,7 @@ module ChemistryKit
53
53
 
54
54
  def find_formula_file
55
55
  Find.find(@formulas_dir) do |path|
56
- return path if path =~ /.*#{@formula}\.rb$/
56
+ return path if path =~ /.*\/#{@formula}\.rb$/
57
57
  end
58
58
  end
59
59
 
@@ -11,6 +11,7 @@ describe ChemistryKit::Formula::FormulaLab do
11
11
 
12
12
  VALID_BASIC_FORMULA_KEY = 'basic_formula'
13
13
  VALID_CHEMIST_FORMULA_KEY = 'chemist_formula'
14
+ VALID_ALTERNATE_CHEMIST_FORMULA = 'alt_chemist_formula'
14
15
 
15
16
  before(:each) do
16
17
  @stub_driver = double 'Selenium::WebDriver::Driver'
@@ -56,4 +57,16 @@ describe ChemistryKit::Formula::FormulaLab do
56
57
  (key == 'ran1' || key == 'ran2').should be_true
57
58
  end
58
59
 
60
+ it 'should deliver formulas with the same instance of chemist if indicated' do
61
+ formula1 = @lab.using(VALID_CHEMIST_FORMULA_KEY).with(VALID_CHEMIST_KEY).mix
62
+ formula2 = @lab.using(VALID_ALTERNATE_CHEMIST_FORMULA).with(VALID_CHEMIST_KEY).mix
63
+
64
+ expect(formula1.chemist).to be(formula2.chemist)
65
+ formula2.change_chemist_type 'other'
66
+ formula1.chemist.type.should eq 'other'
67
+
68
+ formula1.chemist.type = 'new'
69
+ formula2.chemist.type.should eq 'new'
70
+ end
71
+
59
72
  end
data/spec/spec_helper.rb CHANGED
@@ -21,6 +21,7 @@ require_relative '../lib/chemistrykit/configuration'
21
21
 
22
22
  require_relative '../spec/support/formulas/sub_module/basic_formula'
23
23
  require_relative '../spec/support/formulas/sub_module/chemist_formula'
24
+ require_relative '../spec/support/formulas/sub_module/alt_chemist_formula'
24
25
 
25
26
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
26
27
  SimpleCov::Formatter::HTMLFormatter,
@@ -0,0 +1,18 @@
1
+ # Encoding: utf-8
2
+
3
+ require 'chemistrykit/formula/base'
4
+
5
+ module Formulas
6
+ module SubModule
7
+ class AltChemistFormula < ChemistryKit::Formula::Base
8
+ include ChemistryKit::Formula::ChemistAware
9
+ def open(url)
10
+ @driver.get url
11
+ end
12
+
13
+ def change_chemist_type(type)
14
+ chemist.type = type
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,6 @@
1
1
  # Encoding: utf-8
2
2
 
3
3
  require 'chemistrykit/formula/base'
4
- require 'chemistrykit/formula/chemist_aware'
5
4
 
6
5
  module Formulas
7
6
  module SubModule
@@ -96,4 +96,17 @@ describe ChemistryKit::Chemist::Repository::CsvChemistRepository do
96
96
  repo = ChemistryKit::Chemist::Repository::CsvChemistRepository.new(csv_file)
97
97
  repo.should be_an_instance_of ChemistryKit::Chemist::Repository::CsvChemistRepository
98
98
  end
99
+
100
+ it 'should always return the same instance of any chemist' do
101
+ chemist1 = @repo.load_chemist_by_key VALID_USER_KEY
102
+ chemist2 = @repo.load_chemist_by_key VALID_USER_KEY
103
+ expect(chemist2).to be(chemist1)
104
+ end
105
+
106
+ it 'should always return the same instance of any chemist by first type' do
107
+ chemist1 = @repo.load_first_chemist_of_type VALID_USER_TYPE
108
+ chemist2 = @repo.load_first_chemist_of_type VALID_USER_TYPE
109
+ expect(chemist2).to be(chemist1)
110
+ end
111
+
99
112
  end
@@ -28,10 +28,10 @@ describe ChemistryKit::Chemist do
28
28
  @chemist.data.should eq my_key: VALID_VALUE
29
29
  end
30
30
 
31
- it 'should not be able to override the other instance variables' do
32
- @chemist.type = 'other'
33
- @chemist.type.should eq VALID_TYPE
34
- @chemist.data.include?(:type).should be_false
31
+ it 'should not be able to override the key variable' do
32
+ @chemist.key = 'other'
33
+ @chemist.key.should eq VALID_KEY
34
+ @chemist.data.include?(:key).should be_false
35
35
  end
36
36
 
37
37
  it 'should be able to be populated with a hash of arbitrary data' do
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: 3.8.0
4
+ version: 3.8.1
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-08-05 00:00:00.000000000 Z
13
+ date: 2013-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -156,8 +156,7 @@ dependencies:
156
156
  - - ~>
157
157
  - !ruby/object:Gem::Version
158
158
  version: 0.2.1
159
- description: Implemented the chemists feature to add user data management as well
160
- as a simplified strategy for loading formulas
159
+ description: Cleaned up chemists to use same instance in the formulas and bug fixes
161
160
  email:
162
161
  - dave@arrgyle.com
163
162
  - jason@arrgyle.com
@@ -229,6 +228,7 @@ files:
229
228
  - spec/support/chemists.csv
230
229
  - spec/support/config.yaml
231
230
  - spec/support/default_chemists.csv
231
+ - spec/support/formulas/sub_module/alt_chemist_formula.rb
232
232
  - spec/support/formulas/sub_module/basic_formula.rb
233
233
  - spec/support/formulas/sub_module/chemist_formula.rb
234
234
  - spec/support/keyless_chemists.csv
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: 4028715665356631412
265
+ hash: -2034050010631894604
266
266
  requirements: []
267
267
  rubyforge_project:
268
268
  rubygems_version: 1.8.25
@@ -291,6 +291,7 @@ test_files:
291
291
  - spec/support/chemists.csv
292
292
  - spec/support/config.yaml
293
293
  - spec/support/default_chemists.csv
294
+ - spec/support/formulas/sub_module/alt_chemist_formula.rb
294
295
  - spec/support/formulas/sub_module/basic_formula.rb
295
296
  - spec/support/formulas/sub_module/chemist_formula.rb
296
297
  - spec/support/keyless_chemists.csv