Module: Regentanz::TestHelper
- Defined in:
- lib/regentanz/test_helper.rb
Instance Method Summary collapse
-
#create_invalid_xml_response(filename) ⇒ Object
Creates a cache file
filename
with contents of #invalid_xml_response FIXME this is deprecated with the introduction of Regentanz::Cache::File. -
#invalid_xml_response ⇒ Object
Returns an invalid API response that will cause REXML to hickup.
-
#setup_regentanz_test_configuration! ⇒ Object
Default values used for testing.
-
#stub_valid_xml_api_response! ⇒ Object
Stub Net::HTTP.get_response to return a semi-dynamic (ie. current date) xml response-.
-
#valid_xml_response ⇒ Object
Returns a valid xml api reply based upon ./test/support/valid_response.xml.erb.
Instance Method Details
#create_invalid_xml_response(filename) ⇒ Object
Creates a cache file filename
with contents of #invalid_xml_response FIXME this is deprecated with the introduction of Regentanz::Cache::File
36 37 38 |
# File 'lib/regentanz/test_helper.rb', line 36 def create_invalid_xml_response(filename) File.open(filename, "w+") { |f| f.puts invalid_xml_response } end |
#invalid_xml_response ⇒ Object
Returns an invalid API response that will cause REXML to hickup
18 19 20 21 22 23 24 25 |
# File 'lib/regentanz/test_helper.rb', line 18 def invalid_xml_response '<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">' \ "<TITLE>302 Moved</TITLE></HEAD><BODY>\n" \ "<H1>302 Moved</H1>\n" \ "The document has moved\n" \ '<A HREF="http://sorry.google.com/sorry/?continue=http://www.google.com/ig/api%3Fweather%3D86747%252CGermany%26hl%3Dde">here</A>' \ "</BODY></HTML>\n" end |
#setup_regentanz_test_configuration! ⇒ Object
Default values used for testing. Use this in your setup methods. Configuration values can be overriden by supplying a block. See Regentanz::Configuration for supported values.
7 8 9 10 11 12 13 14 15 |
# File 'lib/regentanz/test_helper.rb', line 7 def setup_regentanz_test_configuration! Regentanz.configure do |config| config.retry_ttl = Regentanz::Configuration.default_cache_ttl config.do_not_get_weather = true config.retry_ttl = Regentanz::Configuration.default_retry_ttl config.suppress_stderr_output = true yield config if block_given? # add settings or override above from client end end |
#stub_valid_xml_api_response! ⇒ Object
Stub Net::HTTP.get_response to return a semi-dynamic (ie. current date) xml response-
42 43 44 45 46 |
# File 'lib/regentanz/test_helper.rb', line 42 def stub_valid_xml_api_response! mock_response = mock() mock_response.stubs(:body).returns(valid_xml_response) Net::HTTP.stubs(:get_response).returns(mock_response) end |
#valid_xml_response ⇒ Object
Returns a valid xml api reply based upon ./test/support/valid_response.xml.erb
28 29 30 31 32 |
# File 'lib/regentanz/test_helper.rb', line 28 def valid_xml_response filename = File.join(Regentanz.configuration.cache_dir, '..', 'valid_response.xml.erb') xmlerb = ERB.new(File.open(filename, 'r') { |file| file.read }) xmlerb.result end |