kameleon 0.0.2.pre → 0.0.4

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.
@@ -8,18 +8,35 @@ module Kameleon
8
8
  end
9
9
  end
10
10
 
11
- # def click(link_text, options={:within => DEFAULT_AREA})
12
- # yield if block_given?
13
- # rspec_world.within(options[:within]) do
14
- # begin
15
- # rspec_world.click_on(self_or_translation_for(link_text))
16
- # rescue Capybara::ElementNotFound => e
17
- # attr_value, attr_type = within_value_and_type(options[:within])
18
- # xpath = attr_type ? "//*[@#{attr_type}='#{attr_value}']//*[*='%s']/*" : "//*[#{attr_type}]//*[*='%s']/*"
19
- # rspec_world.find(:xpath, xpath % self_or_translation_for(link_text)).click
20
- # end
21
- # end
22
- #end
11
+ def fill_in(fields)
12
+ fields.each_pair do |value, selector|
13
+ case value
14
+ when :check
15
+ one_or_all(selector).each do |locator|
16
+ session.check locator
17
+ end
18
+ when :uncheck
19
+ one_or_all(selector).each do |locator|
20
+ session.uncheck locator
21
+ end
22
+ else
23
+ session.fill_in selector, :with => value
24
+ end
25
+ end
26
+ end
27
+
28
+ # def click(link_text, options={:within => DEFAULT_AREA})
29
+ # yield if block_given?
30
+ # rspec_world.within(options[:within]) do
31
+ # begin
32
+ # rspec_world.click_on(self_or_translation_for(link_text))
33
+ # rescue Capybara::ElementNotFound => e
34
+ # attr_value, attr_type = within_value_and_type(options[:within])
35
+ # xpath = attr_type ? "//*[@#{attr_type}='#{attr_value}']//*[*='%s']/*" : "//*[#{attr_type}]//*[*='%s']/*"
36
+ # rspec_world.find(:xpath, xpath % self_or_translation_for(link_text)).click
37
+ # end
38
+ # end
39
+ #end
23
40
 
24
41
 
25
42
  end
@@ -1,7 +1,7 @@
1
1
  module Kameleon
2
2
  module Dsl
3
3
  module See
4
- def see(*content)
4
+ def see(*content)
5
5
  options = extract_options(content)
6
6
 
7
7
  case options.class.name
@@ -13,7 +13,27 @@ module Kameleon
13
13
  end
14
14
  when 'Hash'
15
15
  options.each_pair do |value, locator|
16
- session.should rspec_world.have_field(locator, :with => value)
16
+ case value
17
+ when :empty
18
+ one_or_all(locator).each do |selector|
19
+ session.should rspec_world.have_field(selector)
20
+ session.find_field(selector).value.should == ""
21
+ end
22
+ when :checked, :selected
23
+ one_or_all(locator).each do |selector|
24
+ session.should rspec_world.have_checked_field(selector)
25
+ end
26
+ when :unchecked, :unselected
27
+ one_or_all(locator).each do |selector|
28
+ session.should rspec_world.have_unchecked_field(selector)
29
+ end
30
+ when :link, :links
31
+ locator.each_pair do |link_text, url|
32
+ session.should rspec_world.have_link(link_text, :href => url)
33
+ end
34
+ else
35
+ session.should rspec_world.have_field(locator, :with => value)
36
+ end
17
37
  end
18
38
  else
19
39
  raise "Not Implemented Structure #{options} :: #{options.class}"
@@ -9,12 +9,34 @@ module Kameleon
9
9
  include Kameleon::Dsl::See
10
10
  include Kameleon::Dsl::Act
11
11
 
12
+ def initialize(rspec_world, options={})
13
+ @rspec_world = rspec_world
14
+ @driver_name = options.delete(:driver)
15
+ @session_name = options.delete(:session_name)
16
+ @options = options
17
+ set_session
18
+ yield if block_given?
19
+ after_initialization
20
+ end
21
+
12
22
  def visit(page)
13
23
  session.visit(page)
14
24
  end
15
25
 
16
26
  def will(&block)
17
- instance_eval(&block)
27
+ default_selector ?
28
+ within(default_selector, &block) :
29
+ instance_eval(&block)
30
+ end
31
+
32
+ def within(selector, &block)
33
+ session.within(get_selector(selector)) do
34
+ instance_eval(&block)
35
+ end
36
+ end
37
+
38
+ def page_areas
39
+ {}
18
40
  end
19
41
 
20
42
  private
@@ -30,6 +52,22 @@ module Kameleon
30
52
  opts
31
53
  end
32
54
  end
55
+
56
+ def after_initialization
57
+ # stub, should be implemented in subclass
58
+ end
59
+
60
+ def get_selector(selector)
61
+ selector.is_a?(Symbol) ? page_areas[selector] : selector
62
+ end
63
+
64
+ def default_selector
65
+ page_areas[:main]
66
+ end
67
+
68
+ def one_or_all(elements)
69
+ elements.is_a?(Array) ? elements : [elements]
70
+ end
33
71
  end
34
72
  end
35
73
  end
@@ -2,6 +2,35 @@ module Kameleon
2
2
  module User
3
3
  class Base < Abstract
4
4
 
5
+ attr_accessor :user
6
+
7
+ def initialize(rspec_world, options={}, &block)
8
+ super do
9
+ login
10
+ end
11
+ instance_eval(&block) if block_given?
12
+ end
13
+
14
+ def login
15
+ visit user_login_path
16
+ fill_in user_login => 'Email',
17
+ user_password => 'Password'
18
+ click 'Login'
19
+ end
20
+
21
+ private
22
+
23
+ def user_login
24
+ user.email
25
+ end
26
+
27
+ def user_password
28
+ user.password
29
+ end
30
+
31
+ def user_login_path
32
+ new_session_path
33
+ end
5
34
  end
6
35
  end
7
36
  end
@@ -1,13 +1,11 @@
1
1
  module Kameleon
2
2
  module User
3
3
  class Guest < Abstract
4
- def initialize(rspec_world, options={})
5
- @rspec_world = rspec_world
6
- @driver_name = options.delete(:driver)
7
- @session_name = options.delete(:session_name)
8
- @options = options
9
- set_session
10
- session.visit('/') if load_homepage?
4
+ def initialize(rspec_world, options={}, &block)
5
+ super do
6
+ session.visit('/') if load_homepage?
7
+ end
8
+ instance_eval(&block) if block_given?
11
9
  end
12
10
  end
13
11
  end
@@ -3,13 +3,40 @@ require 'spec_helper'
3
3
  describe "Act" do
4
4
  include ::Capybara::DSL
5
5
 
6
- before(:all) do
6
+ before(:each) do
7
7
  Capybara.app = Hey.new(%q{
8
8
  <h1>This is simple app</h1>
9
9
  <a href="next_page.html">Load Next Page</a>
10
10
  <form>
11
+ <label for="xlInput">X-Large input</label>
12
+ <input type="text" size="30" name="xlInput" id="xlInput" value="this is great value" class="xlarge">
13
+
14
+
15
+ <label for="prependedInput2">
16
+ Prepended Checkbox
17
+ <input type="checkbox" size="16" name="prependedInput2" id="prependedInput2" class="mini">
18
+ </label>
19
+ <label class="add-on"></label>
20
+
21
+
22
+ <label for="prependedInput3">Awesome Checkbox</label>
23
+ <input type="checkbox" size="16" name="prependedInput3" id="prependedInput3" class="mini">
24
+
25
+
26
+
27
+
28
+ <label for="appendedInput">Appended checkbox</label>
29
+ <label class="add-on active"><input type="checkbox" value="" id="appendedInput" name="">
30
+
31
+ <label for="some_checkbox_one">Some checkbox</label>
32
+ <input type="checkbox" checked="checked" value="" id="some_checkbox_one" name="">
33
+ <label for="some_checkbox_two">Another checkbox</label>
34
+ <input type="checkbox" checked="checked" value="" id="some_checkbox_two" name="">
35
+ <label for="some_checkbox_three">And One More Checkbox</label>
36
+ <input type="checkbox" checked="checked" value="" id="some_checkbox_three" name="">
11
37
 
12
38
  <input type="submit" value="Save changes" class="btn primary">
39
+
13
40
  <button class="btn" type="reset">Cancel</button>
14
41
 
15
42
  </form>
@@ -32,7 +59,41 @@ describe "Act" do
32
59
 
33
60
  it "allow to chain many clicks - raise error, if at least one of them not found" do
34
61
  lambda {
35
- @user.click "Save changes", "Load Next Page", "Submit", "Load Next Page"
62
+ @user.click "Save changes", "Load Next Page", "Submit", "Load Next Page"
36
63
  }.should raise_error(Capybara::ElementNotFound)
37
64
  end
65
+
66
+ context "fill in form" do
67
+ it "set field value by id" do
68
+ @user.not_see 'WoW' => 'xlInput'
69
+ @user.fill_in 'WoW' => 'xlInput'
70
+ @user.see 'WoW' => 'xlInput'
71
+ end
72
+
73
+ it "set field value by Label title" do
74
+ @user.not_see 'WoW' => 'xlInput'
75
+ @user.fill_in 'WoW' => 'X-Large input'
76
+ @user.see 'WoW' => 'xlInput'
77
+ end
78
+
79
+ context "check box" do
80
+ it "selecting" do
81
+ @user.will do
82
+ see :unchecked => ["Prepended Checkbox", "Appended checkbox", "Awesome Checkbox"]
83
+ fill_in :check => ["Appended checkbox", "Awesome Checkbox"]
84
+ see :checked => ["Appended checkbox", "Awesome Checkbox"],
85
+ :unchecked => "Prepended Checkbox"
86
+ end
87
+ end
88
+
89
+ it "unselecting" do
90
+ @user.will do
91
+ see :checked => ["Some checkbox", "Another checkbox", "And One More Checkbox"]
92
+ fill_in :uncheck => ["And One More Checkbox", "Some checkbox"]
93
+ see :unchecked => ["And One More Checkbox", "Some checkbox"],
94
+ :checked => "Another checkbox"
95
+ end
96
+ end
97
+ end
98
+ end
38
99
  end
@@ -9,11 +9,17 @@ describe "See" do
9
9
  <p>and there is many lines</p>
10
10
  <p>i that app</p>
11
11
 
12
+ <a href="/i-want/to">What you want</a>
13
+
14
+ <a href="/what-i/need">What I need</a>
15
+
12
16
  <form>
13
17
  <fieldset>
14
18
  <legend>Example form legend</legend>
15
19
  <label for="xlInput">X-Large input</label>
16
20
  <input type="text" size="30" name="xlInput" id="xlInput" value="this is great value" class="xlarge">
21
+ <input type="text" size="30" name="xlInput" id="xlInput_two" value="" class="xlarge">
22
+ <input type="text" size="30" name="xlInput" id="xlInput_three" value="" class="xlarge">
17
23
 
18
24
  <label for="normalSelect">Select</label>
19
25
  <select id="normalSelect" name="normalSelect">
@@ -57,7 +63,7 @@ describe "See" do
57
63
  <input type="text" size="16" name="prependedInput2" id="prependedInput2" class="mini">
58
64
 
59
65
  <label for="appendedInput">Appended checkbox</label>
60
- <input type="text" size="16" name="appendedInput" id="appendedInput" class="mini">
66
+ <input type="text" size="16" name="appendedInput" id="appendedInput" checked="checked" class="mini">
61
67
  <label class="add-on active"><input type="checkbox" checked="checked" value="" id="" name=""></label>
62
68
 
63
69
  <label for="fileInput">File input</label>
@@ -68,12 +74,12 @@ describe "See" do
68
74
  <label id="optionsCheckboxes">List of options</label>
69
75
 
70
76
  <label>
71
- <input type="checkbox" value="option1" name="optionsCheckboxes">
77
+ <input type="checkbox" value="option1" name="optionsCheckboxes_one">
72
78
  <span>Option one is this and that&mdash;be sure to include why it's great</span>
73
79
  </label>
74
80
 
75
81
  <label>
76
- <input type="checkbox" value="option2" name="optionsCheckboxes">
82
+ <input type="checkbox" value="option2" checked="checked" name="optionsCheckboxes_two">
77
83
  <span>Option two can also be checked and included in form results</span>
78
84
  </label>
79
85
 
@@ -173,5 +179,64 @@ describe "See" do
173
179
  @user.not_see 'this is not such a great value' => 'xlInput'
174
180
  end
175
181
  end
182
+
183
+ context "values for checkbox'es" do
184
+ context "veirfy status for single checkbox'es'" do
185
+ context "is checked" do
186
+ it "by Label" do
187
+ @user.see :checked => "Appended checkbox"
188
+ end
189
+ it "by dom id" do
190
+ @user.see :checked => "appendedInput"
191
+ end
192
+ end
193
+
194
+ context "is unchecked" do
195
+ it "by Label" do
196
+ @user.see :unchecked => "Prepended checkbox"
197
+ end
198
+ it "by dom id" do
199
+ @user.see :unchecked => "prependedInput"
200
+ end
201
+ end
202
+ end
203
+
204
+ context "should understand status for multiple checkbox'es'" do
205
+ it "checked" do
206
+ @user.see :checked => ["Appended checkbox", "appendedInput", "optionsCheckboxes_two"]
207
+ end
208
+ it "when unchecked" do
209
+ @user.see :unchecked => ["Prepended checkbox", "optionsCheckboxes", "optionsCheckboxes_one"]
210
+ end
211
+
212
+ it "when not all are checked" do
213
+ lambda {
214
+ @user.see :checked => ["Appended checkbox", "appendedInput", "optionsCheckboxes_one"]
215
+ }.should raise_error(RSpec::Expectations::ExpectationNotMetError)
216
+ end
217
+ end
218
+ end
219
+
220
+ context "see empty fields should validate many at once" do
221
+ it "and fails when at least one input are not empty" do
222
+ lambda {
223
+ @user.see :empty => ["xlInput_two", "X-Large input"]
224
+ }.should raise_error(RSpec::Expectations::ExpectationNotMetError)
225
+ end
226
+
227
+ it "succeed when all fields are empty" do
228
+ @user.see :empty => ["xlInput_two", "xlInput_three"]
229
+ end
230
+ end
231
+ context "I can recognize links" do
232
+ it "see when they are placed" do
233
+ @user.see :link => {'What you want' => '/i-want/to'}
234
+ end
235
+ it "throw error if not found" do
236
+ lambda {
237
+ @user.see :link => {'What I need' => '/no-way'}
238
+ }.should raise_error(RSpec::Expectations::ExpectationNotMetError)
239
+ end
240
+ end
176
241
  end
177
242
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Kameleon::User::Base" do
4
+ include ::Capybara::DSL
5
+
6
+ before(:all) do
7
+ Capybara.app = Hey.new("Hello You :-)")
8
+ end
9
+
10
+ # initilization
11
+
12
+ #! overwriting using block for initialization
13
+
14
+ # login in
15
+ end
metadata CHANGED
@@ -1,21 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kameleon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.pre
5
- prerelease: 6
4
+ version: 0.0.4
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michał Czyż [@cs3b]
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-09 00:00:00.000000000 Z
12
+ date: 2011-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name:
16
- - capybara
17
- - rspec
18
- requirement: &10393160 !ruby/object:Gem::Requirement
15
+ name: capybara
16
+ requirement: &15461960 !ruby/object:Gem::Requirement
19
17
  none: false
20
18
  requirements:
21
19
  - - ! '>='
@@ -23,10 +21,21 @@ dependencies:
23
21
  version: '0'
24
22
  type: :runtime
25
23
  prerelease: false
26
- version_requirements: *10393160
24
+ version_requirements: *15461960
27
25
  - !ruby/object:Gem::Dependency
28
26
  name: rspec
29
- requirement: &10392400 !ruby/object:Gem::Requirement
27
+ requirement: &15460940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *15460940
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &15459760 !ruby/object:Gem::Requirement
30
39
  none: false
31
40
  requirements:
32
41
  - - ! '>='
@@ -34,7 +43,18 @@ dependencies:
34
43
  version: '0'
35
44
  type: :development
36
45
  prerelease: false
37
- version_requirements: *10392400
46
+ version_requirements: *15459760
47
+ - !ruby/object:Gem::Dependency
48
+ name: capybara
49
+ requirement: &15457740 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *15457740
38
58
  description: high abstraction dsl for end user perspective tests, kameleon - it's
39
59
  a polish word for chameleon
40
60
  email: michalczyz@gmail.com
@@ -42,14 +62,15 @@ executables: []
42
62
  extensions: []
43
63
  extra_rdoc_files: []
44
64
  files:
45
- - lib/kameleon/user/base.rb
46
65
  - lib/kameleon/user/guest.rb
66
+ - lib/kameleon/user/base.rb
47
67
  - lib/kameleon/user/abstract.rb
48
68
  - lib/kameleon/session/capybara.rb
49
69
  - lib/kameleon/dsl/act.rb
50
70
  - lib/kameleon/dsl/see.rb
51
71
  - lib/kameleon.rb
52
72
  - spec/unit/guest_spec.rb
73
+ - spec/unit/user_base_spec.rb
53
74
  - spec/unit/see_spec.rb
54
75
  - spec/unit/act_spec.rb
55
76
  - spec/sample_rack_app/hey.rb
@@ -71,9 +92,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
92
  required_rubygems_version: !ruby/object:Gem::Requirement
72
93
  none: false
73
94
  requirements:
74
- - - ! '>'
95
+ - - ! '>='
75
96
  - !ruby/object:Gem::Version
76
- version: 1.3.1
97
+ version: '0'
77
98
  requirements: []
78
99
  rubyforge_project:
79
100
  rubygems_version: 1.8.10