Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from bonkydog/jasmine_fixtures.rb
Created June 22, 2014 21:26
Show Gist options
  • Save kivanio/b5156b84c3c85f663694 to your computer and use it in GitHub Desktop.
Save kivanio/b5156b84c3c85f663694 to your computer and use it in GitHub Desktop.
module JasmineFixtures
extend ActiveSupport::Concern
# Saves the markup to a fixture file using the given name
def save_fixture(name)
response.should be_success
fixture_path = File.join(Rails.root, '/spec/javascripts/fixtures')
fixture_file = File.join(fixture_path, name)
fixture = case name
when /\.html$/
response.body.sub(/.*<body/im, '<div').sub(/<\/body>.*/im, "</div>")
when /\.json$/
JSON.pretty_generate(JSON.load(response.body))
else
response.body
end
File.open(fixture_file, 'w') { |file| file.write(fixture)}
end
included do
include RSpec::Rails::ControllerExampleGroup
include ControllerMacros
render_views
before do
DatabaseCleaner.clean_with(:truncation)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment