BigW Consortium Gitlab

env.rb 1.58 KB
Newer Older
1 2
require './spec/simplecov_env'
SimpleCovEnv.start!
3

4 5
ENV['RAILS_ENV'] = 'test'
require './config/environment'
6
require 'rspec/expectations'
7

8 9
if ENV['CI']
  require 'knapsack'
10
  Knapsack::Adapters::SpinachAdapter.bind
11
end
12

13
%w(select2_helper test_env repo_helpers wait_for_requests sidekiq).each do |f|
14 15 16
  require Rails.root.join('spec', 'support', f)
end

17
Dir["#{Rails.root}/features/steps/shared/*.rb"].each { |file| require file }
Nihad Abbasov committed
18

19 20 21
WebMock.allow_net_connect!

Spinach.hooks.before_run do
22
  include RSpec::Mocks::ExampleMethods
23
  RSpec::Mocks.setup
24
  TestEnv.init(mailer: false)
25

26 27 28 29
  # skip pre-receive hook check so we can use
  # web editor and merge
  TestEnv.disable_pre_receive

30
  include FactoryGirl::Syntax::Methods
31
  include GitlabRoutingHelper
32
end
33

34 35
Spinach.hooks.after_scenario do |scenario_data, step_definitions|
  if scenario_data.tags.include?('javascript')
36
    include WaitForRequests
37
    block_and_wait_for_requests_complete
38 39 40
  end
end

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
module StdoutReporterWithScenarioLocation
  # Override the standard reporter to show filename and line number next to each
  # scenario for easy, focused re-runs
  def before_scenario_run(scenario, step_definitions = nil)
    @max_step_name_length = scenario.steps.map(&:name).map(&:length).max if scenario.steps.any?
    name = scenario.name

    # This number has no significance, it's just to line things up
    max_length = @max_step_name_length + 19
    out.puts "\n  #{'Scenario:'.green} #{name.light_green.ljust(max_length)}" \
      " # #{scenario.feature.filename}:#{scenario.line}"
  end
end

Spinach::Reporter::Stdout.prepend(StdoutReporterWithScenarioLocation)