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
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/adaptation/test/test_help.rb', line 178 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
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/adaptation/test/test_help.rb', line 143 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
212 213 214 215 216 217 218 219 |
# File 'lib/adaptation/test/test_help.rb', line 212 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
202 203 204 205 206 207 208 209 |
# File 'lib/adaptation/test/test_help.rb', line 202 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
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 130 131 |
# File 'lib/adaptation/test/test_help.rb', line 96 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/adaptation/test/test_help.rb', line 49 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.
80 81 82 83 84 85 86 87 88 |
# File 'lib/adaptation/test/test_help.rb', line 80 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/adaptation/test/test_help.rb', line 28 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.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/adaptation/test/test_help.rb', line 66 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
246 247 248 |
# File 'lib/adaptation/test/test_help.rb', line 246 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.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/adaptation/test/test_help.rb', line 225 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 |