Class: Parfait::ParfaitArtifact
- Inherits:
-
Object
- Object
- Parfait::ParfaitArtifact
- Defined in:
- lib/parfait/artifact.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#add_check(&block) ⇒ Object
Define the presence check method for a given ParfaitArtifact.
-
#add_generic_present ⇒ Object
Define the secondary
presentdirective based on the user-defined primarycheckdirective. -
#add_present(&block) ⇒ Object
Define the present directive for a given ParfaitArtifact.
-
#check(opts = {}) ⇒ Object
Check if the ParfaitArtifact is present.
-
#initialize(opts = {}) ⇒ ParfaitArtifact
constructor
Constructor for the ParfaitArtifact.
-
#is_present_defined? ⇒ Boolean
Is the present method defined for this Artifact?.
-
#present(opts = {}) ⇒ Object
Is the ParfaitArtifact present?.
-
#verify_presence(error_string) ⇒ Object
Verify the presence of this Artifact.
Constructor Details
#initialize(opts = {}) ⇒ ParfaitArtifact
Constructor for the ParfaitArtifact.
Options
This method does not take any parameters.
No example provided because this method will not be called explicitly. It will strictly be inherited by the Application, Page, Region, and Control classes.
15 16 17 18 |
# File 'lib/parfait/artifact.rb', line 15 def initialize(opts = {}) @check_method = nil @present_method = nil end |
Instance Method Details
#add_check(&block) ⇒ Object
Define the presence check method for a given ParfaitArtifact
Options
block-
specifies the code block to be executed as the check method. This block should return true or false.
Example
sample_page.add_check {
Parfait::browser.h1(:text => "Parfait Example Page").present?
}
33 34 35 36 |
# File 'lib/parfait/artifact.rb', line 33 def add_check(&block) @check_method = block add_generic_present() unless @present_method end |
#add_generic_present ⇒ Object
Define the secondary present directive based on the user-defined primary check directive
Options
None
Example
No example provided - this will be called under the covers when a +check+ directive is defined
98 99 100 101 102 |
# File 'lib/parfait/artifact.rb', line 98 def add_generic_present() add_present { |opts| check(opts) } end |
#add_present(&block) ⇒ Object
Define the present directive for a given ParfaitArtifact
Options
block-
specifies the code block to be executed as the present method. This block should return true or false.
For consistency, it is recommended that the check method be defined with add_check, which will set up the present directive automatically.
Example
sample_page.add_present {
Parfait::browser.h1(:text => "Parfait Example Page").present?
}
68 69 70 |
# File 'lib/parfait/artifact.rb', line 68 def add_present(&block) @present_method = block end |
#check(opts = {}) ⇒ Object
Check if the ParfaitArtifact is present
Options
This method takes a hash of parameters, as defined by the check code block
Example
myapp.page("My Page").check
49 50 51 |
# File 'lib/parfait/artifact.rb', line 49 def check(opts = {}) @check_method.call(opts) end |
#is_present_defined? ⇒ Boolean
Is the present method defined for this Artifact?
Options
This method takes no parameters
Example
myapp.page("My Page").is_present_defined?
115 116 117 118 119 120 121 |
# File 'lib/parfait/artifact.rb', line 115 def is_present_defined?() if @present_method return true else return false end end |
#present(opts = {}) ⇒ Object
Is the ParfaitArtifact present?
Options
This method takes a hash of parameters, as defined by the present code block
Example
myapp.page("My Page").check
83 84 85 |
# File 'lib/parfait/artifact.rb', line 83 def present(opts = {}) @present_method.call(opts) end |
#verify_presence(error_string) ⇒ Object
Verify the presence of this Artifact
Raises an exception with the specified check if this artifact is not present
Options
error_string-
specifies the string to display if the check fails
Example
class Control
def get(opts = {})
verify_presence "Cannot call get directive because presence check for control \"#{@name}\" failed"
return @get_method.call(opts)
end
end
140 141 142 143 144 145 146 |
# File 'lib/parfait/artifact.rb', line 140 def verify_presence(error_string) if is_present_defined? unless present() raise error_string end end end |