Class: MobyBase::TestObject
- Defined in:
- lib/tdriver/base/test_object/abstract.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#sut ⇒ Object
readonly
Returns the value of attribute sut.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#x_path ⇒ Object
readonly
Returns the value of attribute x_path.
Instance Method Summary collapse
-
#<=>(test_object) ⇒ Object
Function to support sorting TestObjects within an array.
-
#==(test_object) ⇒ Object
- Function to verify is DATA of two TestObjects are the same, return TRUE if test_object: instance of MobyBase::TestObject type’s are equal id’s are equal name’s are equal == param test_object
- TestObject other, could be null == returns true
- if TestObjects have same DATA false
-
if TestObjects have different DATA == raises nothing.
-
#eql?(test_object) ⇒ Boolean
- Function to verify is DATA of two TestObjects are the same, Defined in TestObject#== test_object === param test_object
- TestObject other, could be null === returns true
- if TestObjects have same DATA false
-
if TestObjects have different DATA === raises nothing.
-
#hash ⇒ Object
Function to calculate HASH value for a TestObject.
-
#initialize(options) ⇒ TestObject
constructor
Creation of a new TestObject requires options hash to be given to constructor.
-
#inspect ⇒ Object
TODO: document me.
-
#xml_data ⇒ Object
Returns a XML node representing this test object.
-
#xml_data=(xml_object) ⇒ Object
Function to be renamed, possibly refactored.
Constructor Details
#initialize(options) ⇒ TestObject
Creation of a new TestObject requires options hash to be given to constructor.
params
- options
-
Hash containing xml object describing the object and all other required configuration values e.g. test object factory, -adapter etc.
returns
- TestObject
-
new TestObject instance
raises
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 39 def initialize( ) # verify that given argument is type of hash .check_type Hash, 'wrong argument type $1 for TestObject#new (expected $2)' # verify that required keys is found from options hash and initialize the test object with these values @sut = .require_key :sut @test_object_factory = .require_key :test_object_factory @test_object_adapter = .require_key :test_object_adapter @creation_attributes = .require_key :creation_attributes # verify that parent object and parent application is given in options hash @parent = .require_key :parent @parent_application = .require_key :parent_application # store sut id @sut_id = @sut.instance_variable_get :@id # initialize cache object @child_object_cache = TDriver::TestObjectCache.new # empty test object behaviours list @object_behaviours = [] # apply xml object if given; test object type, id and name are retrieved from the xml __send__ :xml_data=, [ :xml_object ] if .has_key?( :xml_object ) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 24 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 24 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
24 25 26 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 24 def parent @parent end |
#sut ⇒ Object (readonly)
Returns the value of attribute sut.
24 25 26 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 24 def sut @sut end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 24 def type @type end |
#x_path ⇒ Object (readonly)
Returns the value of attribute x_path.
24 25 26 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 24 def x_path @x_path end |
Instance Method Details
#<=>(test_object) ⇒ Object
Function to support sorting TestObjects within an array. Mostly for unit testing purposes, as Set is not ordered. should not be used normally. Thus, not documented.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 133 def <=>( test_object ) #self_type = @type #other_type = test_object.type #return -1 if self_type < other_type #return 1 if self_type > other_type #self_name = @name #other_name = test_object.name #return -1 if self_name < other_name #return 1 if self_name > other_name #self_id = @id #other_id = test_object.id #return -1 if self_id < other_id #return 1 if self_id > other_id #0 # optimized version ( ( result = ( @type <=> test_object.type ) ) == 0 ? ( ( result = ( @name <=> test_object.name ) ) == 0 ? @id <=> test_object.id : result ) : result ) end |
#==(test_object) ⇒ Object
Function to verify is DATA of two TestObjects are the same, return TRUE if test_object:
instance of MobyBase::TestObject
type's are equal
id's are equal
name's are equal
param
- test_object
-
TestObject other, could be null
returns
- true
-
if TestObjects have same DATA
- false
-
if TestObjects have different DATA
raises
nothing
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 97 def ==( test_object ) #return false unless test_object.instance_of?( MobyBase::TestObject ) #return false unless @type == test_object.type #return false unless @id == test_object.id #return false unless @name == test_object.name #return true # optimized version test_object.instance_of?( MobyBase::TestObject ) && ( @type == test_object.type ) && ( @id == test_object.id ) && ( @name == test_object.name ) end |
#eql?(test_object) ⇒ Boolean
Function to verify is DATA of two TestObjects are the same, Defined in TestObject#== test_object
param
- test_object
-
TestObject other, could be null
returns
- true
-
if TestObjects have same DATA
- false
-
if TestObjects have different DATA
raises
nothing
78 79 80 81 82 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 78 def eql?( test_object ) __send__ :==, test_object end |
#hash ⇒ Object
Function to calculate HASH value for a TestObject
This is required, as eql? method is being overwritten.
returns
- Fixnum
-
hash number representing current TestObject
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 115 def hash #result = 17 #result = result * 37 + @id.to_i #result = result * 37 + @hash #result = result * 37 + @hash #return result # optimized version #( ( ( 17 * 37 + @id.to_i ) * 37 + @type.hash ) * 37 + @name.hash ) @test_object_adapter.test_object_hash( @id.to_i, @type, @name ) end |
#inspect ⇒ Object
TODO: document me
189 190 191 192 193 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 189 def inspect "#<#{ self.class }:0x#{ ( "%x" % ( object_id.to_i << 1 ) )[ 3 .. -1 ] } @id=\"#{ @id }\" @name=\"#{ @name }\" @parent=#{ @parent.inspect } @sut=#{ @sut.inspect } @type=\"#{ @type }\" @x_path=\"#{ @x_path }\">" end |
#xml_data ⇒ Object
Returns a XML node representing this test object.
returns
- MobyUtil::XML::Element
-
XML representation of this test object
raises
- TestObjectNotFoundError
-
The test object does not exist on the SUT any longer.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 170 def xml_data begin @test_object_adapter.get_xml_element_for_test_object( self ) rescue MobyBase::TestObjectNotFoundError raise MobyBase::TestObjectNotFoundError.new( "The test object (id: #{ @id.inspect }, type: #{ @type.inspect }, name: #{ @name.inspect }) does not exist on #{ @sut.id.inspect } anymore" ) end end |
#xml_data=(xml_object) ⇒ Object
Function to be renamed, possibly refactored
158 159 160 161 162 |
# File 'lib/tdriver/base/test_object/abstract.rb', line 158 def xml_data=( xml_object ) @x_path, @name, @type, @id, @env = @test_object_adapter.get_test_object_identifiers( xml_object, self ) end |