spec_helper.rb 4.04 KB
Newer Older
danielgrippi's avatar
danielgrippi committed
1
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
Raphael's avatar
Raphael committed
2
#   licensed under the Affero General Public License version 3 or later.  See
Raphael's avatar
Raphael committed
3
#   the COPYRIGHT file.
4

5
ENV["RAILS_ENV"] ||= "test"
Jonne Haß's avatar
Jonne Haß committed
6 7 8 9

require 'coveralls'
Coveralls.wear!('rails')

10 11 12 13 14 15 16 17
require File.join(File.dirname(__FILE__), "..", "config", "environment")
require Rails.root.join("spec", "helper_methods")
require Rails.root.join("spec", "spec-doc")
require "rspec/rails"
require "webmock/rspec"
require "factory_girl"
require "sidekiq/testing"
require "shoulda/matchers"
18 19 20 21 22 23

include HelperMethods

Dir["#{File.dirname(__FILE__)}/shared_behaviors/**/*.rb"].each do |f|
  require f
end
24

25 26
ProcessedImage.enable_processing = false
UnprocessedImage.enable_processing = false
Jonne Haß's avatar
Jonne Haß committed
27 28
Rails.application.routes.default_url_options[:host] = AppConfig.pod_uri.host
Rails.application.routes.default_url_options[:port] = AppConfig.pod_uri.port
29

30
def alice
31
  @alice ||= User.find_by(username: "alice")
32
end
33

34
def bob
35
  @bob ||= User.find_by(username: "bob")
36
end
37

38
def eve
39
  @eve ||= User.find_by(username: "eve")
40
end
41

42
def local_luke
43
  @local_luke ||= User.find_by(username: "luke")
44
end
45

46
def local_leia
47
  @local_leia ||= User.find_by(username: "leia")
48
end
49

50
def remote_raphael
51
  @remote_raphael ||= Person.find_by(diaspora_handle: "raphael@remote.net")
52 53
end

54
def peter
55
  @peter ||= User.find_by(username: "peter")
56 57
end

58
def photo_fixture_name
59
  @photo_fixture_name = File.join(File.dirname(__FILE__), "fixtures", "button.png")
60 61
end

theworldbright's avatar
theworldbright committed
62
def jwks_file_path
theworldbright's avatar
theworldbright committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  @jwks_file = File.join(File.dirname(__FILE__), "fixtures", "jwks.json")
end

def valid_client_assertion_path
  @valid_client_assertion = File.join(File.dirname(__FILE__), "fixtures", "valid_client_assertion.txt")
end

def client_assertion_with_tampered_sig_path
  @client_assertion_with_tampered_sig = File.join(File.dirname(__FILE__), "fixtures",
                                                  "client_assertion_with_tampered_sig.txt")
end

def client_assertion_with_nonexistent_kid_path
  @client_assertion_with_nonexistent_kid = File.join(File.dirname(__FILE__), "fixtures",
                                                     "client_assertion_with_nonexistent_kid.txt")
end

def client_assertion_with_nonexistent_client_id_path
  @client_assertion_with_nonexistent_client_id = File.join(File.dirname(__FILE__), "fixtures",
augier's avatar
augier committed
82
                                                           "client_assertion_with_nonexistent_client_id.txt")
theworldbright's avatar
theworldbright committed
83 84
end

85
# Force fixture rebuild
86
FileUtils.rm_f(Rails.root.join("tmp", "fixture_builder.yml"))
87

88 89 90 91 92 93 94 95
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
fixture_builder_file = "#{File.dirname(__FILE__)}/support/fixture_builder.rb"
support_files = Dir["#{File.dirname(__FILE__)}/support/**/*.rb"] - [fixture_builder_file]
support_files.each {|f| require f }
require fixture_builder_file

RSpec.configure do |config|
cmrd Senya's avatar
cmrd Senya committed
96 97
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::IntegrationHelpers, type: :request
98 99
  config.mock_with :rspec

cmrd Senya's avatar
cmrd Senya committed
100 101
  config.example_status_persistence_file_path = "tmp/rspec-persistance.txt"

102 103 104 105 106 107 108 109
  config.render_views
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!

  config.before(:each) do
    I18n.locale = :en
    stub_request(:post, "https://pubsubhubbub.appspot.com/")
    $process_queue = false
Benjamin Neff's avatar
Benjamin Neff committed
110 111
    allow(Workers::SendPublic).to receive(:perform_async)
    allow(Workers::SendPrivate).to receive(:perform_async)
112
  end
113

114 115
  config.expect_with :rspec do |expect_config|
    expect_config.syntax = :expect
116
  end
117

118 119 120
  config.after(:all) do
    `rm -rf #{Rails.root}/tmp/uploads/*`
  end
Jonne Haß's avatar
Jonne Haß committed
121

122 123 124 125
  # Reset overridden settings
  config.after(:each) do
    AppConfig.reset_dynamic!
  end
126 127 128 129 130

  # Reset test mails
  config.after(:each) do
    ActionMailer::Base.deliveries.clear
  end
131

cmrd Senya's avatar
cmrd Senya committed
132 133 134 135 136
  # Reset gon
  config.after(:each) do
    RequestStore.store[:gon].gon.clear unless RequestStore.store[:gon].nil?
  end

137
  config.include FactoryGirl::Syntax::Methods
Jonne Haß's avatar
Jonne Haß committed
138
end
Jonne Haß's avatar
Jonne Haß committed
139 140 141 142 143 144 145

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end