diff options
author | Mike Greiling <mike@pixelcog.com> | 2016-12-30 14:46:41 -0600 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-01-03 10:56:39 -0600 |
commit | 4cd962ec6ec2b037983c1a0d7c1097e8b1f70f52 (patch) | |
tree | 6f1b88ae642e5af03a2b2dc949b3c4630e9f7690 | |
parent | 313aa339b9b2cda26c9160f70444f107e2aafef4 (diff) | |
download | gitlab-ce-4cd962ec6ec2b037983c1a0d7c1097e8b1f70f52.tar.gz |
allow storage of raw string fixtures
-rw-r--r-- | spec/support/javascript_fixtures_helpers.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/spec/support/javascript_fixtures_helpers.rb b/spec/support/javascript_fixtures_helpers.rb index 99e98eebdb4..29dd4de62ff 100644 --- a/spec/support/javascript_fixtures_helpers.rb +++ b/spec/support/javascript_fixtures_helpers.rb @@ -20,11 +20,24 @@ module JavaScriptFixturesHelpers # Public: Store a response object as fixture file # - # response - response object to store + # response - string or response object to store # fixture_file_name - file name to store the fixture in (relative to FIXTURE_PATH) # def store_frontend_fixture(response, fixture_file_name) fixture_file_name = File.expand_path(fixture_file_name, FIXTURE_PATH) + fixture = response.respond_to?(:body) ? parse_response(response) : response + + FileUtils.mkdir_p(File.dirname(fixture_file_name)) + File.write(fixture_file_name, fixture) + end + + private + + # Private: Prepare a response object for use as a frontend fixture + # + # response - response object to prepare + # + def parse_response(response) fixture = response.body response_mime_type = Mime::Type.lookup(response.content_type) @@ -44,7 +57,6 @@ module JavaScriptFixturesHelpers fixture.gsub!(%r{="/}, "=\"http://#{test_host}/") end - FileUtils.mkdir_p(File.dirname(fixture_file_name)) - File.write(fixture_file_name, fixture) + fixture end end |