generate fixtures

This commit is contained in:
Benjamin Neff 2015-06-23 00:01:13 +02:00
parent 762233e48f
commit b1b98adb21
4 changed files with 51 additions and 16 deletions

View file

@ -1,9 +1,23 @@
namespace :ci do namespace :ci do
namespace :travis do namespace :travis do
task prepare_db: %w(db:create db:test:load) task prepare_db: %w(db:create db:test:load)
task prepare: %w(prepare_db) task :prepare_fixtures do
ENV["NO_COVERAGE"] = "true"
Rake::Task["spec:generate_fixtures"].invoke
ENV["NO_COVERAGE"] = "false"
end
task prepare: %w(prepare_db prepare_fixtures)
desc "Run specs" desc "Run specs"
task run: %w(prepare spec) task run: %w(prepare spec)
end end
end end
if defined?(RSpec)
namespace :spec do
desc "Run all specs that generate fixtures for rspec"
RSpec::Core::RakeTask.new(generate_fixtures: "spec:prepare") do |t|
t.rspec_opts = ["--tag fixture"]
end
end
end

View file

@ -8,9 +8,10 @@ module DiasporaFederation
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
end end
it "succeeds" do it "succeeds", fixture: true do
get :host_meta get :host_meta
expect(response).to be_success expect(response).to be_success
save_fixture(response.body, "host-meta")
end end
it "contains the webfinger-template" do it "contains the webfinger-template" do
@ -36,9 +37,10 @@ module DiasporaFederation
end end
describe "GET #legacy_webfinger" do describe "GET #legacy_webfinger" do
it "succeeds when the person exists" do it "succeeds when the person exists", fixture: true do
get :legacy_webfinger, "q" => "alice@localhost:3000" get :legacy_webfinger, "q" => "alice@localhost:3000"
expect(response).to be_success expect(response).to be_success
save_fixture(response.body, "legacy-webfinger")
end end
it "succeeds with 'acct:' in the query when the person exists" do it "succeeds with 'acct:' in the query when the person exists" do
@ -57,7 +59,8 @@ module DiasporaFederation
end end
it "calls WebFinger::WebFinger.from_person" do it "calls WebFinger::WebFinger.from_person" do
expect(WebFinger::WebFinger).to receive(:from_person).and_call_original alice = Person.find_local_by_diaspora_handle("alice@localhost:3000")
expect(WebFinger::WebFinger).to receive(:from_person).with(alice.webfinger_hash).and_call_original
get :legacy_webfinger, "q" => "acct:alice@localhost:3000" get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
end end
end end

View file

@ -1,12 +1,17 @@
require "simplecov" unless ENV["NO_COVERAGE"] == "true"
require "simplecov-rcov" require "simplecov"
SimpleCov.formatters = [ require "simplecov-rcov"
SimpleCov::Formatter::HTMLFormatter, SimpleCov.formatters = [
SimpleCov::Formatter::RcovFormatter SimpleCov::Formatter::HTMLFormatter,
] SimpleCov::Formatter::RcovFormatter
SimpleCov.start do ]
add_filter "spec" SimpleCov.start do
add_filter "test" add_filter "spec"
add_filter "test"
end
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
end end
ENV["RAILS_ENV"] ||= "test" ENV["RAILS_ENV"] ||= "test"
@ -17,9 +22,6 @@ require "rspec/rails"
# load factory girl factories # load factory girl factories
require "factories" require "factories"
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
# Force fixture rebuild # Force fixture rebuild
FileUtils.rm_f(Rails.root.join("tmp", "fixture_builder.yml")) FileUtils.rm_f(Rails.root.join("tmp", "fixture_builder.yml"))

View file

@ -0,0 +1,16 @@
module FixtureGeneration
# Saves the markup to a fixture file using the given name
def save_fixture(markup, name, fixture_path=nil )
fixture_path = Rails.root.join("tmp", "fixtures") unless fixture_path
Dir.mkdir(fixture_path) unless File.exist?(fixture_path)
fixture_file = fixture_path.join("#{name}.fixture.html")
File.open(fixture_file, "w") do |file|
file.puts(markup)
end
end
end
RSpec::Rails::ControllerExampleGroup.class_eval do
include FixtureGeneration
end