Class: Tour
- Inherits:
-
Object
- Object
- Tour
- Extended by:
- Forwardable
- Includes:
- Test::Unit::Assertions, Webrat::Matchers, Webrat::SaveAndOpenPage
- Defined in:
- lib/tour.rb
Overview
A tour is essentially a test suite file. A Tour subclass encapsulates a set of tests that can be done, and may contain helper and support methods for a given task. If you have a two or three paths through a specific area of your website, define a tour for that area and create test_ methods for each type of test to be done.
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#tour_id ⇒ Object
readonly
Returns the value of attribute tour_id.
-
#tour_type ⇒ Object
readonly
Returns the value of attribute tour_type.
-
#tours ⇒ Object
readonly
Returns the value of attribute tours.
-
#webrat_session ⇒ Object
readonly
Returns the value of attribute webrat_session.
Class Method Summary collapse
-
.make_tour(tour_name, host = "http://localhost:3000", tours = [], number = 1, tour_id = nil) ⇒ Object
Factory method, creates the named child class instance.
- .tests(tour_name) ⇒ Object
- .tour?(tour_name) ⇒ Boolean
-
.tours(filter = []) ⇒ Object
Lists tours in tours folder.
Instance Method Summary collapse
-
#after_tour ⇒ Object
after_tour runs once per tour, after all the tests have run.
-
#before_tour ⇒ Object
before_tour runs once per tour, before any tests get run.
-
#initialize(host, tours, number, tour_id) ⇒ Tour
constructor
A new instance of Tour.
- #run_test(test_name) ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
-
#tests ⇒ Object
Returns list of tests in this tour.
- #visit(url, data = nil) ⇒ Object
- #wait(time) ⇒ Object
Constructor Details
#initialize(host, tours, number, tour_id) ⇒ Tour
Returns a new instance of Tour.
73 74 75 76 77 |
# File 'lib/tour.rb', line 73 def initialize(host, tours, number, tour_id) @host, @tours, @number, @tour_id = host, tours, number, tour_id @tour_type = self.send(:class).to_s @webrat_session = Webrat::MechanizeAdapter.new() end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
20 21 22 |
# File 'lib/tour.rb', line 20 def host @host end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
20 21 22 |
# File 'lib/tour.rb', line 20 def number @number end |
#tour_id ⇒ Object (readonly)
Returns the value of attribute tour_id.
20 21 22 |
# File 'lib/tour.rb', line 20 def tour_id @tour_id end |
#tour_type ⇒ Object (readonly)
Returns the value of attribute tour_type.
20 21 22 |
# File 'lib/tour.rb', line 20 def tour_type @tour_type end |
#tours ⇒ Object (readonly)
Returns the value of attribute tours.
20 21 22 |
# File 'lib/tour.rb', line 20 def tours @tours end |
#webrat_session ⇒ Object (readonly)
Returns the value of attribute webrat_session.
20 21 22 |
# File 'lib/tour.rb', line 20 def webrat_session @webrat_session end |
Class Method Details
.make_tour(tour_name, host = "http://localhost:3000", tours = [], number = 1, tour_id = nil) ⇒ Object
Factory method, creates the named child class instance
122 123 124 |
# File 'lib/tour.rb', line 122 def self.make_tour(tour_name,host="http://localhost:3000",tours=[],number=1,tour_id=nil) tour_name.classify.constantize.new(host,tours,number,tour_id) end |
.tests(tour_name) ⇒ Object
113 114 115 |
# File 'lib/tour.rb', line 113 def self.tests(tour_name) Tour.make_tour(tour_name).tests end |
.tour?(tour_name) ⇒ Boolean
117 118 119 |
# File 'lib/tour.rb', line 117 def self.tour?(tour_name) Object.const_defined?(tour_name.classify) && tour_name.classify.constantize.ancestors.include?(Tour) end |
.tours(filter = []) ⇒ Object
Lists tours in tours folder. If a string is given, filters the list by that string. If an array of filter strings is given, returns items that match ANY filter string in the array.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tour.rb', line 102 def self.tours(filter=[]) filter = [filter].flatten # All files in tours folder, stripped to basename, that match any item in filter # I do loves me a long chain. This returns an array containing # 1. All *.rb files in tour folder (recursive) # 2. Each filename stripped to its basename # 3. If you passed in any filters, these basenames are rejected unless they match at least one filter # 4. The filenames remaining are then checked to see if they define a class of the same name that inherits from Tour Dir[File.join('.', 'tours', '**', '*.rb')].map {|fn| File.basename(fn, ".rb")}.select {|fn| filter.size.zero? || filter.any?{|f| fn =~ /#{f}/}}.select {|tour| Tour.tour? tour } end |
Instance Method Details
#after_tour ⇒ Object
after_tour runs once per tour, after all the tests have run
87 |
# File 'lib/tour.rb', line 87 def after_tour; end |
#before_tour ⇒ Object
before_tour runs once per tour, before any tests get run
84 |
# File 'lib/tour.rb', line 84 def before_tour; end |
#run_test(test_name) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/tour.rb', line 132 def run_test(test_name) @test = "test_#{test_name}" raise TourBusException.new("run_test couldn't run test '#{test_name}' because this tour did not respond to :#{@test}") unless respond_to? @test setup send @test teardown end |
#setup ⇒ Object
89 90 |
# File 'lib/tour.rb', line 89 def setup end |
#teardown ⇒ Object
92 93 |
# File 'lib/tour.rb', line 92 def teardown end |
#tests ⇒ Object
Returns list of tests in this tour. (Meant to be run on a subclass instance; returns the list of tests available).
128 129 130 |
# File 'lib/tour.rb', line 128 def tests methods.grep(/^test_/).map {|m| m.sub(/^test_/,'')} end |
#visit(url, data = nil) ⇒ Object
79 80 81 |
# File 'lib/tour.rb', line 79 def visit(url, data=nil) get url, data end |
#wait(time) ⇒ Object
95 96 97 |
# File 'lib/tour.rb', line 95 def wait(time) sleep time.to_i end |