Module: DangerSpecHelper

Defined in:
lib/gitlab/dangerfiles/spec_helper.rb

Class Method Summary collapse

Class Method Details

.fake_dangerObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/dangerfiles/spec_helper.rb', line 32

def self.fake_danger
  Class.new do
    attr_reader :git, :gitlab, :helper

    # rubocop:disable Gitlab/ModuleWithInstanceVariables
    def initialize(git: nil, gitlab: nil, helper: nil)
      @git = git
      @gitlab = gitlab
      @helper = helper
    end

    # rubocop:enable Gitlab/ModuleWithInstanceVariables
  end
end

.testing_dangerfileObject

A stubbed out Dangerfile for use in tests



25
26
27
28
29
30
# File 'lib/gitlab/dangerfiles/spec_helper.rb', line 25

def self.testing_dangerfile
  env = Danger::EnvironmentManager.new(testing_env)
  Danger::Dangerfile.new(env, testing_ui).tap do |dangerfile|
    dangerfile.defined_in_file = Dir.pwd
  end
end

.testing_envObject

Example environment (ENV) that would come from running a PR on TravisCI



15
16
17
18
19
20
21
22
# File 'lib/gitlab/dangerfiles/spec_helper.rb', line 15

def self.testing_env
  {
    "GITLAB_CI" => "true",
    "DANGER_GITLAB_HOST" => "gitlab.example.com",
    "CI_MERGE_REQUEST_IID" => 28_493,
    "DANGER_GITLAB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
  }
end

.testing_uiObject

A silent version of the user interface



9
10
11
# File 'lib/gitlab/dangerfiles/spec_helper.rb', line 9

def self.testing_ui
  Cork::Board.new(silent: true)
end