Skip to content

Instantly share code, notes, and snippets.

@bonkydog
Created October 29, 2012 21:24
Show Gist options
  • Save bonkydog/3976640 to your computer and use it in GitHub Desktop.
Save bonkydog/3976640 to your computer and use it in GitHub Desktop.
jasmine fixture generation
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