letitcrash 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/lib/letitcrash/builders/file_builder.rb +75 -0
  3. data/lib/letitcrash/builders/report_builder.rb +52 -0
  4. data/lib/letitcrash/formatter.rb +29 -0
  5. data/lib/letitcrash/matcher.rb +46 -0
  6. data/lib/letitcrash/matchers/app_veyor.rb +19 -0
  7. data/lib/letitcrash/matchers/base.rb +31 -0
  8. data/lib/letitcrash/matchers/buildkite.rb +19 -0
  9. data/lib/letitcrash/matchers/circle_ci.rb +19 -0
  10. data/lib/letitcrash/matchers/codefresh.rb +20 -0
  11. data/lib/letitcrash/matchers/codeship.rb +19 -0
  12. data/lib/letitcrash/matchers/drone.rb +19 -0
  13. data/lib/letitcrash/matchers/git.rb +27 -0
  14. data/lib/letitcrash/matchers/gitlab_ci.rb +20 -0
  15. data/lib/letitcrash/matchers/jenkins.rb +20 -0
  16. data/lib/letitcrash/matchers/semaphore.rb +19 -0
  17. data/lib/letitcrash/matchers/shippable.rb +19 -0
  18. data/lib/letitcrash/matchers/snap_ci.rb +19 -0
  19. data/lib/letitcrash/matchers/solano_ci.rb +19 -0
  20. data/lib/letitcrash/matchers/team_city.rb +19 -0
  21. data/lib/letitcrash/matchers/travis_ci.rb +19 -0
  22. data/lib/letitcrash/matchers/wercker.rb +20 -0
  23. data/lib/letitcrash/proto/structs.rb +34 -0
  24. data/lib/letitcrash/reporters/stream.rb +19 -0
  25. data/lib/letitcrash/reporters/upload.rb +40 -0
  26. data/lib/letitcrash/sanitizer.rb +37 -0
  27. data/lib/letitcrash/version.rb +5 -0
  28. data/lib/letitcrash.rb +36 -0
  29. data/spec/builders/file_builder_spec.rb +68 -0
  30. data/spec/builders/report_builder_spec.rb +62 -0
  31. data/spec/formatter_spec.rb +57 -0
  32. data/spec/matcher_spec.rb +31 -0
  33. data/spec/matchers/app_veyor_spec.rb +44 -0
  34. data/spec/matchers/base_spec.rb +15 -0
  35. data/spec/matchers/buildkite_spec.rb +44 -0
  36. data/spec/matchers/circle_ci_spec.rb +44 -0
  37. data/spec/matchers/codefresh_spec.rb +34 -0
  38. data/spec/matchers/codeship_spec.rb +44 -0
  39. data/spec/matchers/drone_spec.rb +44 -0
  40. data/spec/matchers/git_spec.rb +60 -0
  41. data/spec/matchers/gitlab_ci_spec.rb +36 -0
  42. data/spec/matchers/jenkins_ci_spec.rb +36 -0
  43. data/spec/matchers/semaphore_spec.rb +44 -0
  44. data/spec/matchers/shared_helpers.rb +17 -0
  45. data/spec/matchers/shippable_spec.rb +44 -0
  46. data/spec/matchers/snap_ci_spec.rb +44 -0
  47. data/spec/matchers/solano_ci_spec.rb +36 -0
  48. data/spec/matchers/team_city_spec.rb +36 -0
  49. data/spec/matchers/travis_ci_spec.rb +44 -0
  50. data/spec/matchers/wercker_spec.rb +42 -0
  51. data/spec/reporters/stream_spec.rb +26 -0
  52. data/spec/reporters/upload_spec.rb +45 -0
  53. data/spec/sanitizer_spec.rb +23 -0
  54. data/spec/spec_helper.rb +19 -0
  55. metadata +374 -0
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'set'
5
+
6
+ require 'parser/current'
7
+
8
+ module LetItCrash
9
+ class Sanitizer
10
+ extend Forwardable
11
+
12
+ def_delegators :@relevant, :include?
13
+
14
+ def self.from_path(path:)
15
+ from_source(source: File.read(path))
16
+ end
17
+
18
+ def self.from_source(source:)
19
+ new(root: Parser::CurrentRuby.parse(source))
20
+ end
21
+
22
+ def initialize(root:)
23
+ @relevant = Set.new
24
+ visit(root)
25
+ end
26
+
27
+ private
28
+
29
+ # This method reeks of :reek:FeatureEnvy.
30
+ def visit(node)
31
+ return unless node.is_a?(Parser::AST::Node)
32
+ loc = node.loc
33
+ @relevant.add(loc.first_line) if loc.expression
34
+ node.children.each(&method(:visit))
35
+ end
36
+ end # class Sanitizer
37
+ end # module LetItCrash
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LetItCrash
4
+ VERSION = '0.1.0'
5
+ end # module LetItCrash
data/lib/letitcrash.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ministry of Matching.
4
+ require 'letitcrash/matchers/base'
5
+ require 'letitcrash/matchers/app_veyor'
6
+ require 'letitcrash/matchers/buildkite'
7
+ require 'letitcrash/matchers/circle_ci'
8
+ require 'letitcrash/matchers/codefresh'
9
+ require 'letitcrash/matchers/codeship'
10
+ require 'letitcrash/matchers/drone'
11
+ require 'letitcrash/matchers/git'
12
+ require 'letitcrash/matchers/gitlab_ci'
13
+ require 'letitcrash/matchers/jenkins'
14
+ require 'letitcrash/matchers/semaphore'
15
+ require 'letitcrash/matchers/shippable'
16
+ require 'letitcrash/matchers/snap_ci'
17
+ require 'letitcrash/matchers/solano_ci'
18
+ require 'letitcrash/matchers/team_city'
19
+ require 'letitcrash/matchers/travis_ci'
20
+ require 'letitcrash/matchers/wercker'
21
+ require 'letitcrash/matcher'
22
+
23
+ # Ministry of Sanitation.
24
+ require 'letitcrash/sanitizer'
25
+
26
+ # Ministry of Construction.
27
+ require 'letitcrash/proto/structs'
28
+ require 'letitcrash/builders/file_builder'
29
+ require 'letitcrash/builders/report_builder'
30
+
31
+ # Ministry of Reporting.
32
+ require 'letitcrash/reporters/stream'
33
+ require 'letitcrash/reporters/upload'
34
+
35
+ require 'letitcrash/formatter'
36
+ require 'letitcrash/version'
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module LetItCrash
6
+ module Builders
7
+ RSpec.describe FileBuilder do
8
+ describe '.build' do
9
+ let(:filename) { 'spec/fixtures/source.file' }
10
+ let(:file) do
11
+ instance_double(
12
+ SimpleCov::SourceFile,
13
+ filename: filename,
14
+ lines: [
15
+ instance_double(
16
+ SimpleCov::SourceFile::Line,
17
+ line_number: 1,
18
+ skipped?: false,
19
+ coverage: 0,
20
+ ),
21
+ instance_double(
22
+ SimpleCov::SourceFile::Line,
23
+ line_number: 2,
24
+ skipped?: false,
25
+ coverage: 0,
26
+ ),
27
+ instance_double(
28
+ SimpleCov::SourceFile::Line,
29
+ line_number: 3,
30
+ skipped?: false,
31
+ coverage: 1,
32
+ )
33
+ ],
34
+ )
35
+ end
36
+ let(:result) { described_class.build(file: file, rewriter: rewriter) }
37
+
38
+ context 'without rewriter' do
39
+ let(:rewriter) { nil }
40
+
41
+ it { expect(result).to be_a Proto::File }
42
+ it { expect(result.coverage).to eq 1.0 }
43
+ it { expect(result.digest).to start_with '73054' }
44
+
45
+ context 'with lines' do
46
+ let(:lines) { result.lines }
47
+
48
+ it { expect(lines.count).to eq 1 }
49
+ it { expect(lines[3]).to eq 1 }
50
+ end # context 'with lines'
51
+
52
+ context 'with path' do
53
+ let(:path) { result.path }
54
+
55
+ it { expect(path.relative).to eq filename }
56
+ it { expect(path.rewritten).to be_empty }
57
+ end # context 'with path'
58
+ end # context 'without rewriter'
59
+
60
+ context 'with rewriter' do
61
+ let(:rewriter) { ->(name) { "bacon/#{name}" } }
62
+
63
+ it { expect(result.path.rewritten).to start_with 'bacon/spec' }
64
+ end # context 'with rewriter'
65
+ end # describe '.build'
66
+ end # RSpec.describe FileBuilder
67
+ end # module Builders
68
+ end # module LetItCrash
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # rubocop:disable RSpec/MessageSpies
6
+ module LetItCrash
7
+ module Builders
8
+ describe ReportBuilder do
9
+ describe '.build' do
10
+ let(:branch) { 'branch' }
11
+ let(:sha) { 'sha' }
12
+ let(:environment) { nil }
13
+ let(:rewriter) { nil }
14
+ let(:report) do
15
+ described_class.build(
16
+ environment: environment,
17
+ result: result,
18
+ rewriter: rewriter,
19
+ )
20
+ end
21
+
22
+ before do
23
+ expect(Matcher)
24
+ .to receive(:new)
25
+ .with(environment: environment)
26
+ .and_return(
27
+ instance_double(
28
+ Matcher,
29
+ matches?: matches,
30
+ branch: branch,
31
+ sha: sha,
32
+ ),
33
+ )
34
+ end
35
+
36
+ context 'with match' do
37
+ let(:matches) { true }
38
+ let(:file) { instance_double(SimpleCov::SourceFile) }
39
+ let(:result) { instance_double(SimpleCov::Result, files: [file]) }
40
+
41
+ before do
42
+ expect(FileBuilder)
43
+ .to receive(:build)
44
+ .with(file: file, rewriter: rewriter)
45
+ .and_return(Proto::File.new)
46
+ end
47
+
48
+ it { expect(report.commit.branch).to eq branch }
49
+ it { expect(report.commit.sha).to eq sha }
50
+ it { expect(report.files.count).to eq 1 }
51
+ end # context 'with match'
52
+
53
+ context 'with no match' do
54
+ let(:matches) { false }
55
+ let(:result) { nil }
56
+
57
+ it { expect { report }.to raise_error ReportBuilder::MatcherMissing }
58
+ end # context 'with no match'
59
+ end # describe '.build'
60
+ end # describe ReportBuilder
61
+ end # module Builders
62
+ end # module LetItCrash
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # rubocop:disable RSpec/MessageSpies
6
+ module LetItCrash
7
+ RSpec.describe Formatter do
8
+ let(:mock_reporter) { instance_double(Reporters::Upload) }
9
+
10
+ describe '#initialize' do
11
+ let(:default_call) do
12
+ expect(Reporters::Upload)
13
+ .to receive(:from_env)
14
+ .and_return(mock_reporter)
15
+ end
16
+
17
+ context 'without reporters' do
18
+ let(:formatter) { described_class.new }
19
+
20
+ before { default_call.once }
21
+
22
+ it { expect(formatter).to be_a described_class }
23
+ end # context 'without reporters'
24
+
25
+ context 'with reporters' do
26
+ let(:formatter) { described_class.new(reporters: [mock_reporter]) }
27
+
28
+ before { default_call.never }
29
+
30
+ it { expect(formatter).to be_a described_class }
31
+ end # context 'with reporters'
32
+ end # describe '#initialize'
33
+
34
+ describe '#format' do
35
+ let(:formatter) { described_class.new(reporters: [mock_reporter]) }
36
+ let(:mock_result) { instance_double(SimpleCov::Result) }
37
+ let(:mock_report) { instance_double(Proto::Report) }
38
+
39
+ before do
40
+ expect(Builders::ReportBuilder)
41
+ .to receive(:build)
42
+ .with(environment: ENV, result: mock_result, rewriter: nil)
43
+ .and_return(mock_report)
44
+
45
+ expect(mock_reporter).to receive(:report).with(mock_report)
46
+ end
47
+
48
+ it { expect { formatter.format(mock_result) }.not_to raise_error }
49
+ end # describe '#format'
50
+
51
+ describe '#new' do
52
+ let(:formatter) { described_class.new(reporters: [mock_reporter]) }
53
+
54
+ it { expect(formatter.new).to eq formatter }
55
+ end # describe '#new'
56
+ end # RSpec.describe Formatter
57
+ end # module LetItCrash
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ # rubocop:disable RSpec/MessageSpies
7
+ module LetItCrash
8
+ RSpec.describe Matcher do
9
+ include_context 'with_branch_and_sha'
10
+ let(:environment) { { 'CF_BRANCH' => branch, 'CF_REVISION' => sha } }
11
+
12
+ context 'when Codefresh matches' do
13
+ it { expect(matcher.matches?).to be_truthy }
14
+ it { expect(matcher.branch).to eq branch }
15
+ it { expect(matcher.sha).to eq sha }
16
+ end # context 'when Codefresh matches'
17
+
18
+ context 'when nothing matches' do
19
+ let(:branch) { nil }
20
+
21
+ before do
22
+ expect(IO)
23
+ .to receive(:popen)
24
+ .with(Matchers::Git::STATUS_CMD)
25
+ .and_return(instance_double(IO, read: 'fatal'))
26
+ end
27
+
28
+ it { expect(matcher.matches?).to be_falsey }
29
+ end # context 'when nothing matches'
30
+ end # RSpec.describe Matcher
31
+ end # module LetItCrash
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe AppVeyor do
9
+ include_context 'with_branch_and_sha'
10
+ let(:ci) { 'true' }
11
+ let(:appveyor) { 'true' }
12
+ let(:environment) do
13
+ {
14
+ 'CI' => ci,
15
+ 'APPVEYOR' => appveyor,
16
+ 'APPVEYOR_REPO_BRANCH' => branch,
17
+ 'APPVEYOR_REPO_COMMIT' => sha
18
+ }
19
+ end
20
+
21
+ it_behaves_like 'reports_branch_and_sha'
22
+
23
+ describe '#matches?' do
24
+ let(:result) { matcher.matches? }
25
+
26
+ context 'with CI and APPVEYOR set to `true` (default)' do
27
+ it { expect(result).to be_truthy }
28
+ end # context 'with CI and APPVEYOR set to `true` (default)'
29
+
30
+ context 'with CI set to nil' do
31
+ let(:ci) { nil }
32
+
33
+ it { expect(result).to be_falsey }
34
+ end # context 'with CI set to nil'
35
+
36
+ context 'with APPVEYOR set to nil' do
37
+ let(:appveyor) { nil }
38
+
39
+ it { expect(result).to be_falsey }
40
+ end # context 'with APPVEYOR set to nil'
41
+ end # describe '#matches?'
42
+ end # RSpec.describe AppVeyor
43
+ end # module Matchers
44
+ end # module LetItCrash
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module LetItCrash
6
+ module Matchers
7
+ RSpec.describe Base do
8
+ let(:matcher) { described_class.new(environment: nil) }
9
+
10
+ it { expect { matcher.matches? }.to raise_error NotImplementedError }
11
+ it { expect { matcher.branch }.to raise_error NotImplementedError }
12
+ it { expect { matcher.sha }.to raise_error NotImplementedError }
13
+ end # RSpec.describe Base
14
+ end # module Matchers
15
+ end # module LetItCrash
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe Buildkite do
9
+ include_context 'with_branch_and_sha'
10
+ let(:ci) { 'true' }
11
+ let(:buildkite) { 'true' }
12
+ let(:environment) do
13
+ {
14
+ 'CI' => ci,
15
+ 'BUILDKITE' => buildkite,
16
+ 'BUILDKITE_BRANCH' => branch,
17
+ 'BUILDKITE_COMMIT' => sha
18
+ }
19
+ end
20
+
21
+ it_behaves_like 'reports_branch_and_sha'
22
+
23
+ describe '#matches?' do
24
+ let(:result) { matcher.matches? }
25
+
26
+ context 'with CI and BUILDKITE set to `true` (default)' do
27
+ it { expect(result).to be_truthy }
28
+ end # context 'with CI and BUILDKITE set to `true` (default)'
29
+
30
+ context 'with CI set to nil' do
31
+ let(:ci) { nil }
32
+
33
+ it { expect(result).to be_falsey }
34
+ end # context 'with CI set to nil'
35
+
36
+ context 'with BUILDKITE set to nil' do
37
+ let(:buildkite) { nil }
38
+
39
+ it { expect(result).to be_falsey }
40
+ end # context 'with BUILDKITE set to nil'
41
+ end # describe '#matches?'
42
+ end # RSpec.describe Buildkite
43
+ end # module Matchers
44
+ end # module LetItCrash
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe CircleCI do
9
+ include_context 'with_branch_and_sha'
10
+ let(:ci) { 'true' }
11
+ let(:circle_ci) { 'true' }
12
+ let(:environment) do
13
+ {
14
+ 'CI' => ci,
15
+ 'CIRCLECI' => circle_ci,
16
+ 'CIRCLE_BRANCH' => branch,
17
+ 'CIRCLE_SHA1' => sha
18
+ }
19
+ end
20
+
21
+ it_behaves_like 'reports_branch_and_sha'
22
+
23
+ describe '#matches?' do
24
+ let(:result) { matcher.matches? }
25
+
26
+ context 'with CI and CIRCLECI set to `true` (default)' do
27
+ it { expect(result).to be_truthy }
28
+ end # context 'with CI and CIRCLECI set to `true` (default)'
29
+
30
+ context 'with CI set to nil' do
31
+ let(:ci) { nil }
32
+
33
+ it { expect(result).to be_falsey }
34
+ end # context 'with CI set to nil'
35
+
36
+ context 'with CIRCLECI set to nil' do
37
+ let(:circle_ci) { nil }
38
+
39
+ it { expect(result).to be_falsey }
40
+ end # context 'with CIRCLECI set to nil'
41
+ end # describe '#matches?'
42
+ end # RSpec.describe CircleCI
43
+ end # module Matchers
44
+ end # module LetItCrash
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe Codefresh do
9
+ include_context 'with_branch_and_sha'
10
+ let(:environment) do
11
+ {
12
+ 'CF_BRANCH' => branch,
13
+ 'CF_REVISION' => sha
14
+ }
15
+ end
16
+
17
+ it_behaves_like 'reports_branch_and_sha'
18
+
19
+ describe '#matches?' do
20
+ let(:result) { matcher.matches? }
21
+
22
+ context 'when CF_BRANCH set (default)' do
23
+ it { expect(result).to be_truthy }
24
+ end # context 'when CF_BRANCH set (default)'
25
+
26
+ context 'when CF_BRANCH not set' do
27
+ let(:branch) { nil }
28
+
29
+ it { expect(result).to be_falsey }
30
+ end # context 'when CF_BRANCH not set'
31
+ end # describe '#matches?'
32
+ end # RSpec.describe Codefresh
33
+ end # module Matchers
34
+ end # module LetItCrash
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe Codeship do
9
+ include_context 'with_branch_and_sha'
10
+ let(:ci) { 'true' }
11
+ let(:ci_name) { 'codeship' }
12
+ let(:environment) do
13
+ {
14
+ 'CI' => ci,
15
+ 'CI_NAME' => ci_name,
16
+ 'CI_BRANCH' => branch,
17
+ 'CI_COMMIT_ID' => sha
18
+ }
19
+ end
20
+
21
+ it_behaves_like 'reports_branch_and_sha'
22
+
23
+ describe '#matches?' do
24
+ let(:result) { matcher.matches? }
25
+
26
+ context 'with CI and CI_NAME set to `codeship` (default)' do
27
+ it { expect(result).to be_truthy }
28
+ end # context 'with CI and CI_NAME set to `codeship` (default)'
29
+
30
+ context 'with CI set to nil' do
31
+ let(:ci) { nil }
32
+
33
+ it { expect(result).to be_falsey }
34
+ end # context 'with CI set to nil'
35
+
36
+ context 'with CI_NAME set to nil' do
37
+ let(:ci_name) { nil }
38
+
39
+ it { expect(result).to be_falsey }
40
+ end # context 'with CI_NAME set to nil'
41
+ end # describe '#matches?'
42
+ end # RSpec.describe Codeship
43
+ end # module Matchers
44
+ end # module LetItCrash
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe Drone do
9
+ include_context 'with_branch_and_sha'
10
+ let(:ci) { 'true' }
11
+ let(:drone) { 'true' }
12
+ let(:environment) do
13
+ {
14
+ 'CI' => ci,
15
+ 'DRONE' => drone,
16
+ 'DRONE_BRANCH' => branch,
17
+ 'DRONE_COMMIT' => sha
18
+ }
19
+ end
20
+
21
+ it_behaves_like 'reports_branch_and_sha'
22
+
23
+ describe '#matches?' do
24
+ let(:result) { matcher.matches? }
25
+
26
+ context 'with CI and DRONE set to `true` (default)' do
27
+ it { expect(result).to be_truthy }
28
+ end # context 'with CI and DRONE set to `true` (default)'
29
+
30
+ context 'with CI set to nil' do
31
+ let(:ci) { nil }
32
+
33
+ it { expect(result).to be_falsey }
34
+ end # context 'with CI set to nil'
35
+
36
+ context 'with DRONE set to nil' do
37
+ let(:drone) { nil }
38
+
39
+ it { expect(result).to be_falsey }
40
+ end # context 'with DRONE set to nil'
41
+ end # describe '#matches?'
42
+ end # RSpec.describe Drone
43
+ end # module Matchers
44
+ end # module LetItCrash
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # rubocop:disable RSpec/MessageSpies
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe Git do
9
+ let(:matcher) { described_class.new(environment: nil) }
10
+
11
+ shared_context 'with_command' do |cmd, result|
12
+ let(:output) { instance_double(IO, read: result) }
13
+
14
+ before { expect(IO).to receive(:popen).with(cmd).and_return(output) }
15
+ end # shared_context 'with_command'
16
+
17
+ describe '#matches?' do
18
+ let(:result) { matcher.matches? }
19
+
20
+ context 'when on a Git branch' do
21
+ include_context 'with_command',
22
+ described_class::STATUS_CMD,
23
+ 'On branch master'
24
+
25
+ it { expect(result).to be_truthy }
26
+ end # context 'when on a Git branch'
27
+
28
+ context 'when not on a Git branch' do
29
+ include_context 'with_command', 'git status', 'fatal: Not a git...'
30
+
31
+ it { expect(result).to be_falsey }
32
+ end # context 'when not on a Git branch'
33
+ end # describe '#matches?'
34
+
35
+ describe '#branch' do
36
+ context 'when HEAD' do
37
+ include_context 'with_command',
38
+ described_class::BRANCH_CMD,
39
+ 'HEAD'
40
+
41
+ it { expect(matcher.branch).to eq 'master' }
42
+ end # context 'when HEAD'
43
+
44
+ context 'with normal branch' do
45
+ include_context 'with_command',
46
+ described_class::BRANCH_CMD,
47
+ 'branch'
48
+
49
+ it { expect(matcher.branch).to eq 'branch' }
50
+ end # context 'with normal branch'
51
+ end # describe '#branch'
52
+
53
+ describe '#sha' do
54
+ include_context 'with_command', described_class::SHA_CMD, 'sha'
55
+
56
+ it { expect(matcher.sha).to eq 'sha' }
57
+ end # describe '#sha'
58
+ end # RSpec.describe Git
59
+ end # module Matchers
60
+ end # module LetItCrash
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'matchers/shared_helpers'
5
+
6
+ module LetItCrash
7
+ module Matchers
8
+ RSpec.describe GitLabCI do
9
+ include_context 'with_branch_and_sha'
10
+ let(:gitlab_ci) { 'true' }
11
+ let(:environment) do
12
+ {
13
+ 'GITLAB_CI' => gitlab_ci,
14
+ 'CI_BUILD_REF_NAME' => branch,
15
+ 'CI_BUILD_REF' => sha
16
+ }
17
+ end
18
+
19
+ it_behaves_like 'reports_branch_and_sha'
20
+
21
+ describe '#matches?' do
22
+ let(:result) { matcher.matches? }
23
+
24
+ context 'with GITLAB_CI set to `true` (default)' do
25
+ it { expect(result).to be_truthy }
26
+ end # context 'with GITLAB_CI set to `true` (default)'
27
+
28
+ context 'with GITLAB_CI set to nil' do
29
+ let(:gitlab_ci) { nil }
30
+
31
+ it { expect(result).to be_falsey }
32
+ end # context 'with GITLAB_CI set to nil'
33
+ end # describe '#matches?'
34
+ end # RSpec.describe GitLabCI
35
+ end # module Matchers
36
+ end # module LetItCrash