generate fixtures
This commit is contained in:
parent
762233e48f
commit
b1b98adb21
4 changed files with 51 additions and 16 deletions
|
|
@ -1,9 +1,23 @@
|
|||
namespace :ci do
|
||||
namespace :travis do
|
||||
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"
|
||||
task run: %w(prepare spec)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ module DiasporaFederation
|
|||
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
|
||||
end
|
||||
|
||||
it "succeeds" do
|
||||
it "succeeds", fixture: true do
|
||||
get :host_meta
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "host-meta")
|
||||
end
|
||||
|
||||
it "contains the webfinger-template" do
|
||||
|
|
@ -36,9 +37,10 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
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"
|
||||
expect(response).to be_success
|
||||
save_fixture(response.body, "legacy-webfinger")
|
||||
end
|
||||
|
||||
it "succeeds with 'acct:' in the query when the person exists" do
|
||||
|
|
@ -57,7 +59,8 @@ module DiasporaFederation
|
|||
end
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
require "simplecov"
|
||||
require "simplecov-rcov"
|
||||
SimpleCov.formatters = [
|
||||
SimpleCov::Formatter::HTMLFormatter,
|
||||
SimpleCov::Formatter::RcovFormatter
|
||||
]
|
||||
SimpleCov.start do
|
||||
add_filter "spec"
|
||||
add_filter "test"
|
||||
unless ENV["NO_COVERAGE"] == "true"
|
||||
require "simplecov"
|
||||
require "simplecov-rcov"
|
||||
SimpleCov.formatters = [
|
||||
SimpleCov::Formatter::HTMLFormatter,
|
||||
SimpleCov::Formatter::RcovFormatter
|
||||
]
|
||||
SimpleCov.start do
|
||||
add_filter "spec"
|
||||
add_filter "test"
|
||||
end
|
||||
|
||||
require "codeclimate-test-reporter"
|
||||
CodeClimate::TestReporter.start
|
||||
end
|
||||
|
||||
ENV["RAILS_ENV"] ||= "test"
|
||||
|
|
@ -17,9 +22,6 @@ require "rspec/rails"
|
|||
# load factory girl factories
|
||||
require "factories"
|
||||
|
||||
require "codeclimate-test-reporter"
|
||||
CodeClimate::TestReporter.start
|
||||
|
||||
# Force fixture rebuild
|
||||
FileUtils.rm_f(Rails.root.join("tmp", "fixture_builder.yml"))
|
||||
|
||||
|
|
|
|||
16
spec/support/fixture_generation.rb
Normal file
16
spec/support/fixture_generation.rb
Normal 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
|
||||
Loading…
Reference in a new issue