gizmo 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,12 +14,25 @@ So, we've gone back to the drawing board and come up with a friendlier, cuddlier
14
14
  **Gizmo** is a simple page model testing framework used and sponsored by [realestate.com.au](http://www.realestate.com.au). The aim of the project is to DRY up testing assertions by abstracting code that defines your page, resulting in a consistent, easy to maintain test suite. The code is maintained by Contributors from REA, and largely based on concepts brought to REA by [Mark Ryall](http://github.com/markryall) and other [thoughtworkers](http://thoughtworks.com.au/)
15
15
 
16
16
 
17
+ Install
18
+ ------------
19
+
20
+ sudo gem install gizmo
21
+
22
+
17
23
  Usage
18
24
  ------------
19
25
  * [with Cucumber](http://wiki.github.com/icaruswings/gizmo/cucumber)
20
26
  * [with RSpec](http://wiki.github.com/icaruswings/gizmo/rspec)
21
27
 
22
28
 
29
+ Development
30
+ ------------
31
+ * Source hosted at [Github](http://github.com/icaruswings/gizmo).
32
+ * Please direct questions, discussions at the [mailing list](http://groups.google.com/group/gizmo-gem).
33
+ * Report issues in the [Github issue tracker](http://github.com/icaruswings/gizmo/issues)
34
+
35
+
23
36
  Contributing
24
37
  ------------
25
38
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -5,8 +5,7 @@ Feature:
5
5
 
6
6
  Scenario: A user can perform a search from the homepage
7
7
  Given a user is on the github homepage
8
- When the user enters "gizmo" into the search box
9
- And the user clicks the magnifying glass icon
8
+ When the user enters "gizmo" into the search box and clicks the magnifying glass icon
10
9
  And the user clicks on the "icaruswings / gizmo" link
11
10
  Then the user is on the "gizmo" github repository details page
12
11
  And the user is on a github repository details page which belongs to "icaruswings"
@@ -2,15 +2,9 @@ Given /^a user is on the github homepage$/ do
2
2
  visit "http://github.com"
3
3
  end
4
4
 
5
- When /^the user enters "([^\"]*)" into the search box$/ do |text|
5
+ When /^the user enters "([^\"]*)" into the search box and clicks the magnifying glass icon$/ do |query|
6
6
  on_page_with :github_search do |page|
7
- fill_in page.search_form.input.attr('name').value, :with => text
8
- end
9
- end
10
-
11
- When /^the user clicks the magnifying glass icon$/ do
12
- on_page_with :github_search do |page|
13
- click page.search_form.submit.attr('alt').value
7
+ page.perform :search, query
14
8
  end
15
9
  end
16
10
 
@@ -26,12 +20,12 @@ end
26
20
 
27
21
  Then /^the user is on the "([^\"]*)" github repository details page$/ do |repo_name|
28
22
  on_page_with :github_repo_details do |page|
29
- page.repo_details.name == repo_name
23
+ page.repo_details.name.should == repo_name
30
24
  end
31
25
  end
32
26
 
33
27
  Then /^the user is on a github repository details page which belongs to "([^\"]*)"$/ do |author|
34
28
  on_page_with :github_repo_details do |page|
35
- page.repo_details.author == author
29
+ page.repo_details.author.should == author
36
30
  end
37
31
  end
@@ -1,5 +1,7 @@
1
1
  module PageWithGithubRepoDetails
2
2
 
3
+ include Gizmo::PageMixin
4
+
3
5
  def valid?
4
6
  has_selector?("div.repohead")
5
7
  end
@@ -11,4 +13,4 @@ module PageWithGithubRepoDetails
11
13
  end
12
14
  end
13
15
 
14
- end
16
+ end
@@ -1,5 +1,7 @@
1
1
  module PageWithGithubSearch
2
2
 
3
+ include Gizmo::PageMixin
4
+
3
5
  def valid?
4
6
  has_selector?("div.search")
5
7
  end
@@ -7,10 +9,15 @@ module PageWithGithubSearch
7
9
  def search_form
8
10
  element_struct do |form|
9
11
  form.container = @document.css("div.search")
10
- form.element = container = form.container.css("form")
12
+ form.element = container= form.container.css("form")
11
13
  form.input = container.css("input[name=q]")
12
14
  form.submit = container.css("input[alt=search]")
13
15
  end
14
16
  end
15
17
 
18
+ define_action :search do |query|
19
+ fill_in search_form.input.attr('name').value, :with => query
20
+ click search_form.submit.attr('alt').value
21
+ end
22
+
16
23
  end
@@ -1,10 +1,11 @@
1
1
  module PageWithGithubSearchResults
2
2
 
3
+ include Gizmo::PageMixin
4
+
3
5
  def valid?
4
6
  has_selector?('div#code_search_results')
5
7
  end
6
8
 
7
-
8
9
  def search_results
9
10
  element_struct do |results|
10
11
  results.repositories = build_repositories
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gizmo}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Luke Cunningham", "Steven Holloway", "Sam Weller"]
12
- s.date = %q{2010-04-10}
12
+ s.date = %q{2010-04-27}
13
13
  s.default_executable = %q{gizmo}
14
14
  s.description = %q{gizmo is a simple page model testing framework used and sponsored by 'realestate.com.au'. The aim of the project is to DRY up your testing assertions by abstracting code that defines your page resulting in a consistent, easy to maintain test suit}
15
15
  s.email = %q{luke@icaruswings.com}
@@ -36,13 +36,13 @@ Gem::Specification.new do |s|
36
36
  "gizmo.gemspec",
37
37
  "lib/gizmo.rb",
38
38
  "lib/gizmo/configuration.rb",
39
- "lib/gizmo/extras.rb",
40
39
  "lib/gizmo/helpers.rb",
41
40
  "lib/gizmo/page.rb",
41
+ "lib/gizmo/page_mixin.rb",
42
42
  "spec/github_site_example_spec.rb",
43
43
  "spec/gizmo/configuration_spec.rb",
44
- "spec/gizmo/extras_spec.rb",
45
44
  "spec/gizmo/helpers_spec.rb",
45
+ "spec/gizmo/page_mixin_spec.rb",
46
46
  "spec/gizmo/page_spec.rb",
47
47
  "spec/pages/page_with_test_mixin_stuff.rb",
48
48
  "spec/spec.opts",
@@ -56,8 +56,8 @@ Gem::Specification.new do |s|
56
56
  s.test_files = [
57
57
  "spec/github_site_example_spec.rb",
58
58
  "spec/gizmo/configuration_spec.rb",
59
- "spec/gizmo/extras_spec.rb",
60
59
  "spec/gizmo/helpers_spec.rb",
60
+ "spec/gizmo/page_mixin_spec.rb",
61
61
  "spec/gizmo/page_spec.rb",
62
62
  "spec/pages/page_with_test_mixin_stuff.rb",
63
63
  "spec/spec_helper.rb"
@@ -8,6 +8,7 @@ module Gizmo
8
8
 
9
9
  autoload :Page, "gizmo/page"
10
10
  autoload :Helpers, "gizmo/helpers"
11
+ autoload :PageMixin, "gizmo/page_mixin"
11
12
 
12
13
  GizmoError = Class.new(StandardError)
13
14
  MixinNotValidError = Class.new(GizmoError)
@@ -16,5 +17,4 @@ module Gizmo
16
17
 
17
18
  end
18
19
 
19
- require "gizmo/configuration"
20
- require "gizmo/extras"
20
+ require "gizmo/configuration"
@@ -3,8 +3,9 @@ module Gizmo
3
3
  module Helpers
4
4
 
5
5
  def on_page &block
6
- raise NilResponseError, "Doh! response object is nil. This generally means your scenario has not yet visited a page!" if response.nil?
7
- yield Page.new(self, response.body, current_url)
6
+ resp = response
7
+ raise NilResponseError, "Doh! response object is nil. This generally means your scenario has not yet visited a page!" if resp.nil?
8
+ yield Page.new(self, resp.body, current_url)
8
9
  end
9
10
 
10
11
  def on_page_with *module_names
@@ -22,11 +23,12 @@ module Gizmo
22
23
 
23
24
  def load_mixin! mixin_name
24
25
  begin
26
+ mixin_dir = Gizmo.configuration.mixin_dir
25
27
  const_name = "PageWith#{mixin_name.to_s.camelize}"
26
- require "#{Gizmo.configuration.mixin_dir}/page_with_#{mixin_name}.rb" unless Object.const_defined?(const_name)
28
+ require "#{mixin_dir}/page_with_#{mixin_name}.rb" unless Object.const_defined?(const_name)
27
29
  Object.const_get(const_name)
28
30
  rescue LoadError
29
- raise MixinNotFoundError, "Expected a page mixin file at #{Gizmo.configuration.mixin_dir}/page_with_#{mixin_name}.rb generate one with `gizmo -g #{mixin_name}`"
31
+ raise MixinNotFoundError, "Expected a page mixin file at #{mixin_dir}/page_with_#{mixin_name}.rb generate one with `gizmo -g #{mixin_name}`"
30
32
  end
31
33
  end
32
34
 
@@ -2,14 +2,9 @@ module Gizmo
2
2
 
3
3
  class Page
4
4
 
5
- attr_reader :mixins, :url, :document
6
-
7
- def extended_with base
8
- @mixins << base
9
- end
5
+ attr_reader :url, :document
10
6
 
11
7
  def initialize driver, content, url
12
- @mixins = []
13
8
  @browser = driver
14
9
  @document = Nokogiri::HTML(content)
15
10
  @url = url
@@ -21,7 +16,7 @@ module Gizmo
21
16
  # then you will get an error message saying "Page did not have mixin #{name}"
22
17
  #eg.
23
18
  # def valid?
24
- # has_selector('some_element_selector')
19
+ # has_selector?('some_element_selector')
25
20
  # end
26
21
  def valid?; true; end
27
22
 
@@ -29,8 +24,26 @@ module Gizmo
29
24
  @document.css(css_selector).length > 0
30
25
  end
31
26
 
27
+ def perform action_name, *params
28
+ method_name = "#{action_name.to_s}_action".to_sym
29
+ raise NoMethodError, "No action named '#{action_name}' has been defined" unless respond_to? method_name
30
+ send(method_name, *params)
31
+ end
32
+
33
+ def method_missing name, *args
34
+ method_name = name.to_sym
35
+ return super unless browser.respond_to?(method_name)
36
+ browser.send(method_name, *args)
37
+ end
38
+
32
39
  private
33
40
 
41
+ def browser; @browser; end
42
+
43
+ def define_action action_name, &block
44
+ self.class.send(:define_method, "#{action_name.to_s}_action".to_sym, &block)
45
+ end
46
+
34
47
  def element_struct
35
48
  open_struct = OpenStruct.new
36
49
  yield open_struct if block_given?
@@ -0,0 +1,21 @@
1
+ module Gizmo
2
+
3
+ module PageMixin
4
+
5
+ def self.included base
6
+ base.extend(InstanceMethods)
7
+ end
8
+
9
+ module InstanceMethods
10
+
11
+ private
12
+
13
+ def define_action action_name, &block
14
+ define_method("#{action_name.to_s}_action", &block)
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -25,7 +25,7 @@ describe "Github" do
25
25
 
26
26
  it "should have a text input which accepts a search query" do
27
27
  on_page_with :github_search do |page|
28
- fill_in page.search_form.input.attr('name').value, :with => 'gizmo'
28
+ page.perform :search, 'gizmo'
29
29
  end
30
30
  end
31
31
 
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Gizmo" do
4
+
5
+ before(:all) do
6
+ module MyModule
7
+ include Gizmo::PageMixin
8
+ define_action(:tell) { |message| message }
9
+ end
10
+ @obj = Gizmo::Page.new({},'',{}).extend(MyModule)
11
+ end
12
+
13
+ describe "PageMixin" do
14
+
15
+ describe "#define_action" do
16
+ it "should be a private method" do
17
+ MyModule.private_methods.should include 'define_action'
18
+ end
19
+
20
+ it "should define a new action" do
21
+ MyModule.send(:define_action, :x) { |x| x }
22
+ @obj.should respond_to :x_action
23
+ end
24
+
25
+ it "should call a defined action and return the expected response" do
26
+ @obj.perform(:tell, "hello world").should == "hello world"
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -21,19 +21,11 @@ describe "Gizmo" do
21
21
  @response ||= mock('response', :body => mock_response)
22
22
  end
23
23
 
24
- def current_url
25
- 'http://www.example.com'
26
- end
27
-
28
- @page = Gizmo::Page.new(self, response.body, current_url)
24
+ @page = Gizmo::Page.new(self, response.body, 'http://www.example.com')
29
25
  end
30
26
 
31
27
  describe "attributes and accessors" do
32
28
 
33
- it "should have an instance variable @mixins" do
34
- @page.instance_variable_get(:@mixins).should_not be_nil
35
- end
36
-
37
29
  it "should have an instance variable @document" do
38
30
  @page.instance_variable_get(:@document).should_not be_nil
39
31
  end
@@ -48,36 +40,13 @@ describe "Gizmo" do
48
40
  end
49
41
  end
50
42
 
43
+
51
44
  describe "@url" do
52
45
  it "should return the expected string" do
53
46
  @page.instance_variable_get(:@url).should == "http://www.example.com"
54
47
  end
55
48
  end
56
49
 
57
- describe "@mixins" do
58
- it "should be accessible with .mixins" do
59
- @page.mixins.should equal @page.instance_variable_get(:@mixins)
60
- end
61
-
62
- it "should return an array" do
63
- @page.mixins.should be_an(Array)
64
- end
65
-
66
- it "should be writable using instance_variable_set" do
67
- mixins = @page.mixins << :new_mixin
68
- @page.instance_variable_set :@mixins, mixins
69
- @page.mixins.should include :new_mixin
70
- end
71
- end
72
-
73
- it "should have an attribute reader for @mixins" do
74
- @page.should respond_to(:mixins)
75
- end
76
-
77
- it "should not have an attribute writer for @mixins" do
78
- @page.should_not respond_to(:mixins=)
79
- end
80
-
81
50
  it "should have an attribute reader for @url" do
82
51
  @page.should respond_to(:url)
83
52
  end
@@ -94,20 +63,28 @@ describe "Gizmo" do
94
63
  @page.should_not respond_to(:document=)
95
64
  end
96
65
 
66
+ it "should have a private attribute reader for browser" do
67
+ @page.private_methods.should include "browser"
68
+ end
69
+
97
70
  end
98
71
 
99
- describe "#extended_with" do
72
+ it "should have a #perform method" do
73
+ @page.should respond_to :perform
74
+ end
100
75
 
101
- it "should add the mixin name to the Page's @mixin instance attribute" do
102
- on_page_with(:my_mixin, :my_other_mixin) do |page|
103
- [:my_mixin, :my_other_mixin].each { |m| page.mixins.should include Object.const_get("PageWith#{m.to_s.camelize}") }
104
- end
76
+ describe "delegate session methods to @browser" do
77
+ it "should be a private method" do
78
+ @page.should_not respond_to :click_link
105
79
  end
106
80
 
81
+ it "should define a new action within page" do
82
+ @page.send(:define_action, :tell) { |message| message }
83
+ @page.should respond_to :tell_action
84
+ end
107
85
  end
108
86
 
109
87
  describe "#has_selector?" do
110
-
111
88
  it "should return true if @document contains one or more elements matching the selector" do
112
89
  @page.has_selector?('p.one_of_these').should be_true
113
90
  @page.has_selector?('p.two_of_these').should be_true
@@ -116,11 +93,10 @@ describe "Gizmo" do
116
93
  it "should return false if @document does not contain one or more elements matching the selector" do
117
94
  @page.has_selector?('p.does_not_exist').should be_false
118
95
  end
119
-
120
96
  end
121
97
 
122
- describe "#element_struct" do
123
98
 
99
+ describe "#element_struct" do
124
100
  it "should provide an override for OpenStruct to make it yield to a block" do
125
101
  @page.send(:element_struct) { |o| o.should be_an OpenStruct }
126
102
  end
@@ -128,7 +104,6 @@ describe "Gizmo" do
128
104
  it "should return an OpenStruct if not given a block" do
129
105
  @page.send(:element_struct).should be_an OpenStruct
130
106
  end
131
-
132
107
  end
133
108
 
134
109
  end
@@ -7,7 +7,7 @@ require 'spec/autorun'
7
7
  begin require 'redgreen' unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
8
8
 
9
9
  Spec::Runner.configure do |config|
10
- include Gizmo::Helpers
10
+ config.include Gizmo::Helpers
11
11
 
12
12
  config.before do
13
13
  Gizmo.configure do |config|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Luke Cunningham
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-04-10 00:00:00 +10:00
19
+ date: 2010-04-27 00:00:00 +10:00
20
20
  default_executable: gizmo
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -144,13 +144,13 @@ files:
144
144
  - gizmo.gemspec
145
145
  - lib/gizmo.rb
146
146
  - lib/gizmo/configuration.rb
147
- - lib/gizmo/extras.rb
148
147
  - lib/gizmo/helpers.rb
149
148
  - lib/gizmo/page.rb
149
+ - lib/gizmo/page_mixin.rb
150
150
  - spec/github_site_example_spec.rb
151
151
  - spec/gizmo/configuration_spec.rb
152
- - spec/gizmo/extras_spec.rb
153
152
  - spec/gizmo/helpers_spec.rb
153
+ - spec/gizmo/page_mixin_spec.rb
154
154
  - spec/gizmo/page_spec.rb
155
155
  - spec/pages/page_with_test_mixin_stuff.rb
156
156
  - spec/spec.opts
@@ -188,8 +188,8 @@ summary: simple page model testing framework
188
188
  test_files:
189
189
  - spec/github_site_example_spec.rb
190
190
  - spec/gizmo/configuration_spec.rb
191
- - spec/gizmo/extras_spec.rb
192
191
  - spec/gizmo/helpers_spec.rb
192
+ - spec/gizmo/page_mixin_spec.rb
193
193
  - spec/gizmo/page_spec.rb
194
194
  - spec/pages/page_with_test_mixin_stuff.rb
195
195
  - spec/spec_helper.rb
@@ -1,8 +0,0 @@
1
- # Override the #extended method on Module so it calls a method
2
- # #extended_with if it exists - we use this to manage an array
3
- # of modules that have been mixed in to a Gizmo::Page object
4
- class Module
5
- def extended mixin
6
- mixin.extended_with(self) if mixin.respond_to?(:extended_with)
7
- end
8
- end
@@ -1,13 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Gizmo" do
4
-
5
- describe "Extras" do
6
-
7
- it "should override #extended in the base Module class" do
8
- Module.new.should respond_to :extended
9
- end
10
-
11
- end
12
-
13
- end