tapestry 0.1.0 → 0.2.0

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,93 @@
1
+ require "tapestry/situation"
2
+
3
+ module Tapestry
4
+ module Ready
5
+ include Situation
6
+
7
+ # The ReadyAttributes contains methods that can be called directly on the
8
+ # interface class definition. These are very much like the attributes
9
+ # that are used for defining aspects of the pages, such as `url_is` or
10
+ # `title_is`. These attributes are included separately so as to maintain
11
+ # more modularity.
12
+ module ReadyAttributes
13
+ # This method will provide a list of the ready_validations that have
14
+ # been defined. This list will contain the list in the order that the
15
+ # validations were defined in.
16
+ def ready_validations
17
+ if superclass.respond_to?(:ready_validations)
18
+ superclass.ready_validations + _ready_validations
19
+ else
20
+ _ready_validations
21
+ end
22
+ end
23
+
24
+ # When this attribute method is specified on an interface, it will
25
+ # append the validation provided by the block.
26
+ def page_ready(&block)
27
+ _ready_validations << block
28
+ end
29
+
30
+ alias page_ready_when page_ready
31
+
32
+ private
33
+
34
+ def _ready_validations
35
+ @_ready_validations ||= []
36
+ end
37
+ end
38
+
39
+ def self.included(caller)
40
+ caller.extend(ReadyAttributes)
41
+ end
42
+
43
+ # If a ready validation fails, the message reported by that failure will
44
+ # be captured in the `ready_error` accessor.
45
+ attr_accessor :ready, :ready_error
46
+
47
+ # The `when_ready` method is called on an instance of an interface. This
48
+ # executes the provided validation block after the page has been loaded.
49
+ # The Ready object instance is yielded into the block.
50
+ #
51
+ # Calls to the `ready?` method use a poor-man's cache approach. The idea
52
+ # here being that when a page has confirmed that it is ready, meaning that
53
+ # no ready validations have failed, that information is stored so that any
54
+ # subsequent calls to `ready?` do not query the ready validations again.
55
+ def when_ready(&_block)
56
+ already_marked_ready = ready
57
+
58
+ no_ready_check_possible unless block_given?
59
+
60
+ self.ready = ready?
61
+ not_ready_validation(ready_error || 'NO REASON PROVIDED') unless ready
62
+ yield self
63
+ ensure
64
+ self.ready = already_marked_ready
65
+ end
66
+
67
+ # The `ready?` method is used to check if the page has been loaded
68
+ # successfully, which means that none of the ready validations have
69
+ # indicated failure.
70
+ #
71
+ # When `ready?` is called, the blocks that were stored in the above
72
+ # `ready_validations` array are instance evaluated against the current
73
+ # page instance.
74
+ def ready?
75
+ self.ready_error = nil
76
+ return true if ready
77
+ ready_validations_pass?
78
+ end
79
+
80
+ private
81
+
82
+ # This method checks if the ready validations that have been specified
83
+ # have passed. If any ready validation fails, no matter if others have
84
+ # succeeded, this method immediately returns false.
85
+ def ready_validations_pass?
86
+ self.class.ready_validations.all? do |validation|
87
+ passed, message = instance_eval(&validation)
88
+ self.ready_error = message if message && !passed
89
+ passed
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,77 @@
1
+ require "tapestry/errors"
2
+
3
+ module Tapestry
4
+ module Situation
5
+ private
6
+
7
+ def url_is_empty
8
+ puts "PROBLEM: url_is attribute empty.\n" \
9
+ "The url_is attribute is empty on the definition " \
10
+ "'#{retrieve_class(caller)}'.\n\n"
11
+ raise Tapestry::Errors::NoUrlForDefinition
12
+ end
13
+
14
+ def no_url_provided
15
+ puts "PROBLEM: no url provided.\n" \
16
+ "You called a '#{retrieve_method(caller)}' action but the " \
17
+ "definition '#{self.class}' does not have a url_is attribute.\n" \
18
+ "Either provide the url_is attribute or pass the url as an " \
19
+ "argument to the visit call.\n\n"
20
+ raise Tapestry::Errors::NoUrlForDefinition
21
+ end
22
+
23
+ def url_match_is_empty
24
+ puts "PROBLEM: url_matches attribute empty.\n" \
25
+ "The url_matches attribute is empty on the definition " \
26
+ "'#{retrieve_class(caller)}'.\n\n"
27
+ raise Tapestry::Errors::NoUrlMatchForDefinition
28
+ end
29
+
30
+ def no_url_match_is_possible
31
+ puts "PROBLEM: No url_is or url_matches attribute.\n" \
32
+ "You called a '#{retrieve_method(caller)}' action but the " \
33
+ "definition '#{self.class}' has no url_is attribute nor a " \
34
+ "url_matches attribute.\n\n"
35
+ raise Tapestry::Errors::NoUrlMatchPossible
36
+ end
37
+
38
+ def title_is_empty
39
+ puts "PROBLEM: title_is attribute empty.\n" \
40
+ "The title_is attribute is empty on the definition " \
41
+ "'#{retrieve_class(caller)}'.\n\n"
42
+ raise Tapestry::Errors::NoTitleForDefinition
43
+ end
44
+
45
+ def no_title_is_provided
46
+ puts "PROBLEM: No title provided.\n" \
47
+ "You called a '#{retrieve_method(caller)}' action but the " \
48
+ "definition '#{self.class}' does not have a title_is attribute.\n\n"
49
+ raise Tapestry::Errors::NoTitleForDefinition
50
+ end
51
+
52
+ def not_ready_validation(message)
53
+ puts "PROBLEM: A ready validation error was encountered.\n" \
54
+ "A ready validation failed to validate. The ready check was " \
55
+ "on the '#{self.class}' definition. " \
56
+ "The reason provided was:\n" \
57
+ "#{message}.\n\n"
58
+ raise Tapestry::Errors::PageNotValidatedError, message
59
+ end
60
+
61
+ def no_ready_check_possible
62
+ puts "PROBLEM: A when ready call has no action.\n" \
63
+ "You called a when_ready on a definition but did not provide " \
64
+ "any action for it. Add a block with logic that should be " \
65
+ "executed if the ready check passes.\n\n"
66
+ raise Tapestry::Errors::NoBlockForWhenReady
67
+ end
68
+
69
+ def retrieve_class(caller)
70
+ caller[1][/`.*'/][8..-3]
71
+ end
72
+
73
+ def retrieve_method(caller)
74
+ caller[0][/`.*'/][1..-2]
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,24 @@
1
1
  module Tapestry
2
- VERSION = "0.1.0".freeze
2
+ module_function
3
+
4
+ VERSION = "0.2.0".freeze
5
+
6
+ def version
7
+ """
8
+ Tapestry v#{Tapestry::VERSION}
9
+ watir: #{gem_version('watir')}
10
+ selenium-webdriver: #{gem_version('selenium-webdriver')}
11
+ """
12
+ end
13
+
14
+ def dependencies
15
+ Gem.loaded_specs.values.map { |spec| "#{spec.name} #{spec.version}\n" }
16
+ .uniq.sort.join(",").split(",")
17
+ end
18
+
19
+ def gem_version(name)
20
+ Gem.loaded_specs[name].version
21
+ rescue NoMethodError
22
+ puts "No gem loaded for #{name}."
23
+ end
3
24
  end
data/tapestry.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.14"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "simplecov"
27
28
  spec.add_development_dependency "rubocop"
28
29
  spec.add_development_dependency "pry"
29
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapestry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Nyman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -114,9 +128,22 @@ files:
114
128
  - Rakefile
115
129
  - bin/console
116
130
  - bin/setup
131
+ - examples/tapestry-data-set.rb
132
+ - examples/tapestry-events.rb
133
+ - examples/tapestry-factory.rb
117
134
  - examples/tapestry-simple.rb
118
135
  - lib/tapestry.rb
136
+ - lib/tapestry/attribute.rb
119
137
  - lib/tapestry/element.rb
138
+ - lib/tapestry/errors.rb
139
+ - lib/tapestry/extensions/data_setter.rb
140
+ - lib/tapestry/extensions/dom_observer.js
141
+ - lib/tapestry/extensions/dom_observer.rb
142
+ - lib/tapestry/extensions/watir_elements.rb
143
+ - lib/tapestry/factory.rb
144
+ - lib/tapestry/interface.rb
145
+ - lib/tapestry/ready.rb
146
+ - lib/tapestry/situation.rb
120
147
  - lib/tapestry/version.rb
121
148
  - tapestry.gemspec
122
149
  homepage: https://github.com/jeffnyman/tapestry
@@ -124,7 +151,7 @@ licenses:
124
151
  - MIT
125
152
  metadata: {}
126
153
  post_install_message: "\n(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)\n
127
- \ Tapestry 0.1.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::) (::)
154
+ \ Tapestry 0.2.0 has been installed.\n(::) (::) (::) (::) (::) (::) (::) (::) (::)
128
155
  (::) (::) (::)\n "
129
156
  rdoc_options: []
130
157
  require_paths: