|
6 | 6 | subject { described_class.new(config, context) }
|
7 | 7 | let(:result) { double('result') }
|
8 | 8 |
|
9 |
| - before do |
10 |
| - result.stub(:stdout).and_return(email) |
11 |
| - subject.stub(:execute).and_return(result) |
12 |
| - end |
13 |
| - |
14 |
| - context 'when user has no email' do |
15 |
| - let(:email) { '' } |
| 9 | + shared_examples_for 'author email check' do |
| 10 | + context 'when user has no email' do |
| 11 | + let(:email) { '' } |
16 | 12 |
|
17 |
| - it { should fail_hook } |
18 |
| - end |
| 13 | + it { should fail_hook } |
| 14 | + end |
19 | 15 |
|
20 |
| - context 'when user has an invalid email' do |
21 |
| - let(:email) { 'Invalid Email' } |
| 16 | + context 'when user has an invalid email' do |
| 17 | + let(:email) { 'Invalid Email' } |
22 | 18 |
|
23 |
| - it { should fail_hook } |
24 |
| - end |
| 19 | + it { should fail_hook } |
| 20 | + end |
25 | 21 |
|
26 |
| - context 'when user has a valid email' do |
27 |
| - let(:email) { 'email@example.com' } |
| 22 | + context 'when user has a valid email' do |
| 23 | + let(:email) { 'email@example.com' } |
28 | 24 |
|
29 |
| - it { should pass } |
30 |
| - end |
| 25 | + it { should pass } |
| 26 | + end |
31 | 27 |
|
32 |
| - context 'when a custom pattern is specified' do |
33 |
| - let(:config) do |
34 |
| - super().merge(Overcommit::Configuration.new( |
35 |
| - 'PreCommit' => { |
36 |
| - 'AuthorEmail' => { |
37 |
| - 'pattern' => '^[^@]+@brigade\.com$' |
| 28 | + context 'when a custom pattern is specified' do |
| 29 | + let(:config) do |
| 30 | + super().merge(Overcommit::Configuration.new( |
| 31 | + 'PreCommit' => { |
| 32 | + 'AuthorEmail' => { |
| 33 | + 'pattern' => '^[^@]+@brigade\.com$' |
| 34 | + } |
38 | 35 | }
|
39 |
| - } |
40 |
| - )) |
41 |
| - end |
| 36 | + )) |
| 37 | + end |
42 | 38 |
|
43 |
| - context 'and the email does not match the pattern' do |
44 |
| - let(:email) { 'email@example.com' } |
| 39 | + context 'and the email does not match the pattern' do |
| 40 | + let(:email) { 'email@example.com' } |
45 | 41 |
|
46 |
| - it { should fail_hook } |
| 42 | + it { should fail_hook } |
| 43 | + end |
| 44 | + |
| 45 | + context 'and the email matches the pattern' do |
| 46 | + let(:email) { 'email@brigade.com' } |
| 47 | + |
| 48 | + it { should pass } |
| 49 | + end |
47 | 50 | end
|
| 51 | + end |
48 | 52 |
|
49 |
| - context 'and the email matches the pattern' do |
50 |
| - let(:email) { 'email@brigade.com' } |
| 53 | + context 'when email is set via config' do |
| 54 | + before do |
| 55 | + result.stub(:stdout).and_return(email) |
| 56 | + subject.stub(:execute).and_return(result) |
| 57 | + end |
51 | 58 |
|
52 |
| - it { should pass } |
| 59 | + it_should_behave_like 'author email check' |
| 60 | + end |
| 61 | + |
| 62 | + context 'when email is set via environment variable' do |
| 63 | + around do |example| |
| 64 | + Overcommit::Utils.with_environment 'GIT_AUTHOR_EMAIL' => email do |
| 65 | + example.run |
| 66 | + end |
53 | 67 | end
|
| 68 | + |
| 69 | + it_should_behave_like 'author email check' |
54 | 70 | end
|
55 | 71 | end
|
0 commit comments