page_navigation 0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format doc
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm --create use 1.9.3-p194@page-object
2
+
@@ -0,0 +1,2 @@
1
+ === Version 0.1 / 2013-1-25
2
+ * This is the initial release of this gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ # Specify your gem's dependencies in page_navigation.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeffrey S. Morgan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # PageNavigation
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'page_navigation'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install page_navigation
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.ruby_opts = "-I lib:spec"
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+ task :spec
9
+
10
+ task :lib do
11
+ $LOAD_PATH.unshift(File.expand_path("lib", File.dirname(__FILE__)))
12
+ end
13
+
14
+ task :default => :spec
@@ -0,0 +1,103 @@
1
+ require "page_navigation/version"
2
+ require "page_navigation/routes"
3
+
4
+ #
5
+ # Implements basic navigation capabilities for a collection of classes
6
+ # that implement a PageObject like pattern.
7
+ #
8
+ # In order to use these two methods you must define routes. A route
9
+ # is cimply an array of Class/Method calls and can contain parameters
10
+ # that can be passed to the methods. Here is an example:
11
+ #
12
+ # @example Example routes defined in env.rb
13
+ # MyNavigator.routes = {
14
+ # :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
15
+ # :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
16
+ # }
17
+ #
18
+ # Notice the first entry of :anouther_route is passing an argument
19
+ # to the method.
20
+ #
21
+ # The user must also maintain an instance variable named @current_page
22
+ # which points to the current object in the array.
23
+ #
24
+ module PageNavigation
25
+
26
+ def self.included(cls)
27
+ cls.extend PageNavigation::Routes
28
+ end
29
+
30
+
31
+ #
32
+ # Navigate to a specific page following a predefined path.
33
+ #
34
+ # This method requires a lot of setup. See the documentation for
35
+ # this module. Once the setup is complete you can navigate to a
36
+ # page traversing through all other pages along the way. It will
37
+ # call the method you specified in the routes for each
38
+ # page as it navigates. Using the example setup defined in the
39
+ # documentation above you can call the method two ways:
40
+ #
41
+ # @example
42
+ # page.navigate_to(PageThree) # will use the default path
43
+ # page.navigate_to(PageThree, :using => :another_route)
44
+ #
45
+ # @param [PageObject] a class that implements the PageObject pattern.
46
+ # @param [Hash] a hash that contains an element with the key
47
+ # :using. This will be used to lookup the route. It has a
48
+ # default value of :default.
49
+ # @param [block] an optional block to be called
50
+ # @return [PageObject] the page you are navigating to
51
+ #
52
+ def navigate_to(page_cls, how = {:using => :default}, &block)
53
+ path = path_for how
54
+ to_index = find_index_for(path, page_cls)-1
55
+ navigate_through_pages(path[0..to_index])
56
+ on(page_cls, &block)
57
+ end
58
+
59
+ #
60
+ # Same as navigate_to except it will start at the @current_page
61
+ # instead the beginning of the path.
62
+ #
63
+ # @param [PageObject] a class that implements the PageObject pattern.
64
+ # @param [Hash] a hash that contains an element with the key
65
+ # :using. This will be used to lookup the route. It has a
66
+ # default value of :default.
67
+ # @param [block] an optional block to be called
68
+ # @return [PageObject] the page you are navigating to
69
+ #
70
+ def continue_navigation_to(page_cls, how = {:using => :default}, &block)
71
+ path = path_for how
72
+ from_index = find_index_for(path, @current_page.class)+1
73
+ to_index = find_index_for(path, page_cls)-1
74
+ navigate_through_pages(path[from_index..to_index])
75
+ on(page_cls, &block)
76
+ end
77
+
78
+
79
+ private
80
+
81
+ def path_for(how)
82
+ path = self.class.routes[how[:using]]
83
+ fail("PageFactory route :#{how[:using].to_s} not found") unless path
84
+ path
85
+ end
86
+
87
+ def navigate_through_pages(pages)
88
+ pages.each do |cls, method, *args|
89
+ page = on(cls)
90
+ fail("Navigation method not specified on #{cls}.") unless page.respond_to? method
91
+ page.send method unless args
92
+ page.send method, *args if args
93
+ end
94
+ end
95
+
96
+ def find_index_for(path, item)
97
+ path.find_index { |each| each[0] == item}
98
+ end
99
+
100
+ def self.included(cls)
101
+ cls.extend PageNavigation::Routes
102
+ end
103
+ end
@@ -0,0 +1,10 @@
1
+ module PageNavigation
2
+ module Routes
3
+ attr_accessor :routes
4
+
5
+ def routes=(routes)
6
+ raise("You must provide a :default route") unless routes[:default]
7
+ @routes = routes
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module PageNavigation
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'page_navigation/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "page_navigation"
8
+ gem.version = PageNavigation::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = ["Jeffrey S. Morgan"]
11
+ gem.email = ["jeff.morgan@leandog.com"]
12
+ gem.homepage = "http://github.com/cheezy/page_naigation"
13
+ gem.description = %q{Provides basic navigation through a collection of items that use the PageObject pattern.}
14
+ gem.summary = %q{Provides basic navigation through a collection of items that use the PageObject pattern.}
15
+
16
+ gem.rubyforge_project = "page_naigation"
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+
23
+ gem.add_development_dependency 'rspec', '>= 2.12.0'
24
+
25
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ class FactoryTestPage
4
+ end
5
+
6
+ class AnotherPage
7
+ end
8
+
9
+ class YetAnotherPage
10
+ end
11
+
12
+ class TestNavigator
13
+ include PageNavigation
14
+ attr_accessor :current_page
15
+
16
+ def on(cls)
17
+ cls.new
18
+ end
19
+
20
+ def class_from_string(str)
21
+ str.split('::').inject(Object) do |mod, class_name|
22
+ mod.const_get(class_name)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe PageNavigation do
28
+ before(:each) do
29
+ @navigator = TestNavigator.new
30
+ end
31
+
32
+ it "should raise an error when you do not provide a default route" do
33
+ expect { TestNavigator.routes = {:another => []} }.to raise_error
34
+ end
35
+
36
+ it "should store the routes" do
37
+ routes = ['a', 'b', 'c']
38
+ TestNavigator.routes = {:default => routes}
39
+ TestNavigator.routes[:default].should == routes
40
+ end
41
+
42
+ it "should navigate to a page calling the default methods" do
43
+ pages = [[FactoryTestPage, :a_method], [AnotherPage, :b_method]]
44
+ TestNavigator.routes = {:default => pages}
45
+ fake_page = double('a_page')
46
+ FactoryTestPage.should_receive(:new).and_return(fake_page)
47
+ fake_page.should_receive(:a_method)
48
+ @navigator.navigate_to(AnotherPage).class.should == AnotherPage
49
+ end
50
+
51
+ it "should pass parameters to methods when navigating" do
52
+ pages = [[FactoryTestPage, :a_method, 'blah'], [AnotherPage, :b_method]]
53
+ TestNavigator.routes = {:default => pages}
54
+ fake_page = double('a_page')
55
+ FactoryTestPage.should_receive(:new).and_return(fake_page)
56
+ fake_page.should_receive(:a_method).with('blah')
57
+ @navigator.navigate_to(AnotherPage).class.should == AnotherPage
58
+ end
59
+
60
+ it "should fail when it does not find a proper route" do
61
+ TestNavigator.routes = {:default => ['a'], :another => ['b']}
62
+ expect { @navigator.navigate_to(AnotherPage, :using => :no_route) }.to raise_error
63
+ end
64
+
65
+ it "should fail when no default method specified" do
66
+ TestNavigator.routes = {
67
+ :default => [[FactoryTestPage, :a_method], [AnotherPage, :b_method]]
68
+ }
69
+ fake_page = double('a_page')
70
+ FactoryTestPage.should_receive(:new).and_return(fake_page)
71
+ fake_page.should_receive(:respond_to?).with(:a_method).and_return(false)
72
+ expect { @navigator.navigate_to(AnotherPage) }.to raise_error
73
+ end
74
+
75
+ it "should know how to continue routng from a location" do
76
+ TestNavigator.routes = {
77
+ :default => [[FactoryTestPage, :a_method],
78
+ [AnotherPage, :b_method],
79
+ [YetAnotherPage, :c_method]]
80
+ }
81
+ fake_page = double('a_page')
82
+ AnotherPage.should_receive(:new).and_return(fake_page)
83
+ fake_page.should_receive(:respond_to?).with(:b_method).and_return(true)
84
+ fake_page.should_receive(:b_method)
85
+ @navigator.current_page = FactoryTestPage.new
86
+ FactoryTestPage.should_not_receive(:new)
87
+ @navigator.continue_navigation_to(YetAnotherPage).class.should == YetAnotherPage
88
+ end
89
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'rspec'
6
+ require 'page_navigation'
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: page_navigation
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeffrey S. Morgan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ description: Provides basic navigation through a collection of items that use the
31
+ PageObject pattern.
32
+ email:
33
+ - jeff.morgan@leandog.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - .rspec
40
+ - .rvmrc
41
+ - ChangeLog
42
+ - Gemfile
43
+ - LICENSE.txt
44
+ - README.md
45
+ - Rakefile
46
+ - lib/page_navigation.rb
47
+ - lib/page_navigation/routes.rb
48
+ - lib/page_navigation/version.rb
49
+ - page_navigation.gemspec
50
+ - spec/lib/page_navigation_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: http://github.com/cheezy/page_naigation
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
65
+ - 0
66
+ hash: 2015481616432211171
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ segments:
74
+ - 0
75
+ hash: 2015481616432211171
76
+ requirements: []
77
+ rubyforge_project: page_naigation
78
+ rubygems_version: 1.8.24
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Provides basic navigation through a collection of items that use the PageObject
82
+ pattern.
83
+ test_files:
84
+ - spec/lib/page_navigation_spec.rb
85
+ - spec/spec_helper.rb