Class: Test::Unit::TestCase
- Defined in:
- lib/adaptation/test/fake_fixtures.rb,
lib/adaptation/test/test_help.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#assert_database_not_present(db_settings_hash) ⇒ Object
Asserts a database doesn’t exist.
-
#assert_database_present(db_settings_hash) ⇒ Object
Asserts a database exists.
-
#assert_file_not_present(file) ⇒ Object
Asserts a file doesn’t exist.
-
#assert_file_present(file) ⇒ Object
Asserts a file exists.
-
#assert_message_published(xml_message) ⇒ Object
Asserts that a message has been published in test environment.
-
#assert_not_parsed(message_symbol) ⇒ Object
Asserts that a message in a xml fixture file is converted into an Adaptation::Message that if serialized again to xml is not equivalent to the xml data in the initial fixture file.
-
#assert_not_validates(message_symbol) ⇒ Object
Asserts that an Adaptation::Message message, build from a xml fixture file doesn’t pass all the validations specified in the class definition.
-
#assert_parsed(message_symbol) ⇒ Object
Asserts that a message in a xml fixture file is converted into an Adaptation::Message that if serialized again to xml is equivalent to the xml data in the initial fixture file.
-
#assert_validates(message_symbol) ⇒ Object
Asserts that an Adaptation::Message message build from a xml fixture file passes all the validations specified in the class definition.
-
#get_message_from_fixture(message_symbol) ⇒ Object
Retuns a message object from a fixture, without processing it.
-
#message(message_symbol) ⇒ Object
Builds a message from a xml fixture file and processes it the same way mesages from the mom are processed by adaptation, but using a test environment.
Class Method Details
.fixtures(symbol) ⇒ Object
2 3 |
# File 'lib/adaptation/test/fake_fixtures.rb', line 2 def self.fixtures symbol end |
Instance Method Details
#assert_database_not_present(db_settings_hash) ⇒ Object
Asserts a database doesn’t exist. To do so this method tries to establish a connection with the specified database. Connection information must be provided with a hash. This method assert if connection fails, but that could also mean that provided connection hash is wrong. The connection options are the same as in assert_database_present:
:database
-
=> database name
:host
-
=> database host
:username
-
=> database user
:password
-
=> database password
:adapter
-
=> database type (default is "mysql")
These options correspond to those in Activerecord::Base.establish_conection
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/adaptation/test/test_help.rb', line 176 def assert_database_not_present db_settings_hash update_activerecord_test_configuration db_settings_hash ActiveRecord::Base.remove_connection ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ADAPTOR_ENV]) database_exists = true begin connection = ActiveRecord::Base.connection rescue Exception => e database_exists = false end error = error, "? database shouldn't exist", ActiveRecord::Base.configurations[ADAPTOR_ENV][:database] assert_block error do !database_exists end end |
#assert_database_present(db_settings_hash) ⇒ Object
Asserts a database exists. To do so this method tries to establish a connection with the specified database. Conection information must be provided with a hash:
:database
-
=> database name
:host
-
=> database host
:username
-
=> database user
:password
-
=> database password
:adapter
-
=> database type (default is "mysql")
These options correspond to those in Activerecord::Base.establish_conection
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/adaptation/test/test_help.rb', line 141 def assert_database_present db_settings_hash update_activerecord_test_configuration db_settings_hash ActiveRecord::Base.remove_connection ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ADAPTOR_ENV]) database_exists = true begin connection = ActiveRecord::Base.connection rescue Exception => e database_exists = false end error = error, "? database not found", ActiveRecord::Base.configurations[ADAPTOR_ENV][:database] assert_block error do database_exists end end |
#assert_file_not_present(file) ⇒ Object
Asserts a file doesn’t exist
210 211 212 213 214 215 216 217 |
# File 'lib/adaptation/test/test_help.rb', line 210 def assert_file_not_present file error = error, "? shouldn't exist", file assert_block error do !File.exists?(file) end end |
#assert_file_present(file) ⇒ Object
Asserts a file exists
200 201 202 203 204 205 206 207 |
# File 'lib/adaptation/test/test_help.rb', line 200 def assert_file_present file error = error, "? not found", file assert_block error do File.exists?(file) end end |
#assert_message_published(xml_message) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/adaptation/test/test_help.rb', line 94 def = if .is_a?(String) # build Message object with xml_data = [1..(.index(/(>| )/) - 1)] = Adaptation::Message.get_class_object(.capitalize) = .to_object() end # check for all messages "published" in the mom (that's file /tmp/mom.txt), # if any line corresponds to the message passed as a parameter. = false expected = published = "" File.open(ADAPTOR_ROOT + '/test/mocks/test/mom.txt', 'r').each{ |line| = REXML::Document.new line published = line.chop expected = .to_xml.to_s if compare_xml_elements .root, .to_xml = true break end } error = (error, "? message not published:\n \ Expected : ?\n \ Published: ?\n", .class, expected, published) assert_block error do end end |
#assert_not_parsed(message_symbol) ⇒ Object
Asserts that a message in a xml fixture file is converted into an Adaptation::Message that if serialized again to xml is not equivalent to the xml data in the initial fixture file. An Adaptation::Message object cretaed from a xml fixture, will only have the xml tags specified in its class definition (using has_one, has_many, has_text…) so this assertion can be useful to check that undesired xml tags are filtered.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/adaptation/test/test_help.rb', line 47 def assert_not_parsed data, = parsed_data = REXML::Document.new data error = error, "? shouldn't be parsed ok:\n data: ?\n real: ?", .to_s, parsed_data.to_s, .to_xml.to_s assert_block error do !compare_xml_elements parsed_data.root, .to_xml end end |
#assert_not_validates(message_symbol) ⇒ Object
Asserts that an Adaptation::Message message, build from a xml fixture file doesn’t pass all the validations specified in the class definition.
78 79 80 81 82 83 84 85 86 |
# File 'lib/adaptation/test/test_help.rb', line 78 def assert_not_validates data, = error = error, "? message shouldn't validate", .to_s assert_block error do !.valid? end end |
#assert_parsed(message_symbol) ⇒ Object
Asserts that a message in a xml fixture file is converted into an Adaptation::Message that if serialized again to xml is equivalent to the xml data in the initial fixture file. An Adaptation::Message object cretaed from a xml fixture, will only have the xml tags specified in its class definition (using has_one, has_many, has_text…) so this assertion can be useful to check that the class is defined correctly.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/adaptation/test/test_help.rb', line 26 def assert_parsed data, = parsed_data = REXML::Document.new data error = error, "? not parsed ok:\n initial: ?\n parsed: ?", .to_s, parsed_data.to_s, .to_xml.to_s assert_block error do compare_xml_elements parsed_data.root, .to_xml end end |
#assert_validates(message_symbol) ⇒ Object
Asserts that an Adaptation::Message message build from a xml fixture file passes all the validations specified in the class definition.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/adaptation/test/test_help.rb', line 64 def assert_validates data, = error = error, "invalid message ?", .to_s .clear_errors assert_block error do .valid? end end |
#get_message_from_fixture(message_symbol) ⇒ Object
Retuns a message object from a fixture, without processing it
244 245 246 |
# File 'lib/adaptation/test/test_help.rb', line 244 def ()[1] end |
#message(message_symbol) ⇒ Object
Builds a message from a xml fixture file and processes it the same way mesages from the mom are processed by adaptation, but using a test environment. Published messages will be published to a mock MOM.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/adaptation/test/test_help.rb', line 223 def # build a message object from fixture , = # load mock objects Dir["test/mocks/test/*.rb"].each do |f| require f end # clean mom (delete mom.txt file) mom_mock_file = ADAPTOR_ROOT + '/test/mocks/test/mom.txt' if File.exists? mom_mock_file File.delete mom_mock_file end Adaptation::Base.new.process end |