rspec-command 1.0.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.
@@ -0,0 +1,106 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fileutils'
18
+
19
+ require 'spec_helper'
20
+
21
+ describe RSpecCommand::MatchFixture::FileList do
22
+ let(:path) { nil }
23
+ subject { described_class.new(temp_path, path) }
24
+ def write(path)
25
+ path = File.join(temp_path, path)
26
+ FileUtils.mkdir_p(File.dirname(path))
27
+ IO.write(path, '')
28
+ end
29
+
30
+ context 'with a single file' do
31
+ let(:path) { 'data.txt' }
32
+ before { write('data.txt') }
33
+ its(:full_path) { is_expected.to eq File.join(temp_path, 'data.txt') }
34
+ its(:files) { is_expected.to eq ['data.txt'] }
35
+ its(:full_files) { is_expected.to eq [File.join(temp_path, 'data.txt')] }
36
+ end # /context with a single file
37
+
38
+ context 'with a non-existent file' do
39
+ let(:path) { 'data.txt' }
40
+ its(:full_path) { is_expected.to eq File.join(temp_path, 'data.txt') }
41
+ its(:files) { is_expected.to eq [] }
42
+ its(:full_files) { is_expected.to eq [] }
43
+ end # /context with a non-existent file
44
+
45
+ context 'with a folder' do
46
+ let(:path) { 'sub' }
47
+ before { write('sub/one.txt'); write('sub/two.txt') }
48
+ its(:full_path) { is_expected.to eq File.join(temp_path, 'sub') }
49
+ its(:files) { is_expected.to eq ['one.txt', 'two.txt'] }
50
+ its(:full_files) do
51
+ is_expected.to eq [
52
+ File.join(temp_path, 'sub/one.txt'),
53
+ File.join(temp_path, 'sub/two.txt'),
54
+ ]
55
+ end
56
+ end # /context with a folder
57
+
58
+ describe '#relative' do
59
+ let(:file) { }
60
+ let(:root) { File.join(temp_path, file) }
61
+ let(:path) { nil }
62
+ before { write(file) }
63
+ subject { described_class.new(root, path).relative(File.join(temp_path, file)) }
64
+
65
+ context 'with a single file' do
66
+ let(:file) { 'data.txt' }
67
+ it { is_expected.to eq 'data.txt' }
68
+ end # /context with a single file
69
+
70
+ context 'with a nested file' do
71
+ let(:file) { 'data/inner.txt' }
72
+ it { is_expected.to eq 'inner.txt' }
73
+ end # /context with a nested file
74
+
75
+ context 'with a folder root' do
76
+ let(:file) { 'data/inner.txt' }
77
+ let(:root) { temp_path }
78
+ it { is_expected.to eq 'data/inner.txt' }
79
+ end # /context with a folder root
80
+ end # /describe #relative
81
+
82
+ describe '#absolute' do
83
+ let(:file) { }
84
+ let(:root) { File.join(temp_path, file) }
85
+ let(:path) { nil }
86
+ before { write(file) }
87
+ subject { described_class.new(root, path).absolute(file) }
88
+
89
+ context 'with a single file' do
90
+ let(:file) { 'data.txt' }
91
+ it { is_expected.to eq File.join(temp_path, 'data.txt') }
92
+ end # /context with a single file
93
+
94
+ context 'with a nested file' do
95
+ let(:file) { 'inner.txt' }
96
+ let(:root) { File.join(temp_path, 'data', 'inner.txt') }
97
+ it { is_expected.to eq File.join(temp_path, 'data', 'inner.txt') }
98
+ end # /context with a nested file
99
+
100
+ context 'with a folder root' do
101
+ let(:file) { 'data/inner.txt' }
102
+ let(:root) { temp_path }
103
+ it { is_expected.to eq File.join(temp_path, 'data', 'inner.txt') }
104
+ end # /context with a folder root
105
+ end # /describe #absolute
106
+ end
@@ -0,0 +1 @@
1
+ Fixture data.
@@ -0,0 +1 @@
1
+ Subfixture 1.
@@ -0,0 +1 @@
1
+ Subfixture 2.
@@ -0,0 +1 @@
1
+ Subfixture inner 1.
@@ -0,0 +1 @@
1
+ Subfixture inner 2.
@@ -0,0 +1 @@
1
+ Subfixture nested.
@@ -0,0 +1,186 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe RSpecCommand::MatchFixture do
20
+ def write(path, content)
21
+ path = File.join(temp_path, path)
22
+ FileUtils.mkdir_p(File.dirname(path))
23
+ IO.write(path, content)
24
+ end
25
+
26
+ describe 'in an example' do
27
+ subject { nil }
28
+
29
+ context 'with a single file' do
30
+ before { write('data.txt', "Fixture data.\n") }
31
+ it { is_expected.to match_fixture('data.txt') }
32
+ end # /context with a single file
33
+
34
+ context 'with a non-existent file' do
35
+ it { is_expected.to_not match_fixture('data.txt') }
36
+ end # /context with a non-existent file
37
+
38
+ context 'with a single file that does not match' do
39
+ before { write('data.txt', "Other data.\n") }
40
+ it { is_expected.to_not match_fixture('data.txt') }
41
+ end # /context with a single file that does not match
42
+
43
+ context 'with a single file in a folder' do
44
+ before { write('sub1.txt', "Subfixture 1.\n") }
45
+ it { is_expected.to match_fixture('sub/sub1.txt') }
46
+ end # /context with a single file in a folder
47
+
48
+ context 'with a folder' do
49
+ before do
50
+ write('sub1.txt', "Subfixture 1.\n")
51
+ write('sub2.txt', "Subfixture 2.\n")
52
+ end
53
+ it { is_expected.to match_fixture('sub') }
54
+ end # /context with a folder
55
+
56
+ context 'with a folder with an extra file' do
57
+ before do
58
+ write('sub1.txt', "Subfixture 1.\n")
59
+ write('sub2.txt', "Subfixture 2.\n")
60
+ write('sub3.txt', "Subfixture 3.\n")
61
+ end
62
+ it { is_expected.to_not match_fixture('sub') }
63
+ end # /context with a folder with an extra file
64
+
65
+ context 'with a folder with a missing file' do
66
+ before do
67
+ write('sub1.txt', "Subfixture 1.\n")
68
+ end
69
+ it { is_expected.to_not match_fixture('sub') }
70
+ end # /context with a folder with a missing file
71
+
72
+ context 'with a folder that does not match' do
73
+ before do
74
+ write('sub1.txt', "Subfixture 1.\n")
75
+ write('sub2.txt', "Subfixture 3.\n")
76
+ end
77
+ it { is_expected.to_not match_fixture('sub') }
78
+ end # /context with a folder with a missing file
79
+
80
+ context 'with a nested folder' do
81
+ before do
82
+ write('sub_nested.txt', "Subfixture nested.\n")
83
+ write('sub_inner/sub_inner1.txt', "Subfixture inner 1.\n")
84
+ write('sub_inner/sub_inner2.txt', "Subfixture inner 2.\n")
85
+ end
86
+ it { is_expected.to match_fixture('sub_nested') }
87
+ end # /context with a nested folder
88
+
89
+ context 'with a nested folder with an extra file' do
90
+ before do
91
+ write('sub_nested.txt', "Subfixture nested.\n")
92
+ write('sub_inner/sub_inner1.txt', "Subfixture inner 1.\n")
93
+ write('sub_inner/sub_inner2.txt', "Subfixture inner 2.\n")
94
+ write('sub_inner/sub_inner3.txt', "Subfixture inner 2.\n")
95
+ end
96
+ it { is_expected.to_not match_fixture('sub_nested') }
97
+ end # /context with a nested folder with an extra file
98
+
99
+ context 'with a nested folder with a missing file' do
100
+ before do
101
+ write('sub_nested.txt', "Subfixture nested.\n")
102
+ write('sub_inner/sub_inner1.txt', "Subfixture inner 1.\n")
103
+ end
104
+ it { is_expected.to_not match_fixture('sub_nested') }
105
+ end # /context with a nested folder with a missing file
106
+
107
+ context 'with a nested folder that does not match' do
108
+ before do
109
+ write('sub_nested.txt', "Subfixture nested.\n")
110
+ write('sub_inner/sub_inner1.txt', "Subfixture inner 1.\n")
111
+ write('sub_inner/sub_inner2.txt', "Subfixture inner 3.\n")
112
+ end
113
+ it { is_expected.to_not match_fixture('sub_nested') }
114
+ end # /context with a nested folder that does not match
115
+ end # /describe in an example
116
+
117
+ describe '#failure_message' do
118
+ let(:path) { nil }
119
+ subject { described_class.new(File.expand_path('../fixtures', __FILE__), temp_path, path).failure_message }
120
+
121
+ context 'with a non-existent file' do
122
+ let(:path) { 'data.txt' }
123
+ it { is_expected.to include('data.txt is not found') }
124
+ end # /context with a non-existent file
125
+
126
+ context 'with a single file that does not match' do
127
+ let(:path) { 'data.txt' }
128
+ before { write('data.txt', "Other data.\n") }
129
+ it { is_expected.to include('data.txt does not match fixture:') }
130
+ it { is_expected.to include('-Fixture data.') }
131
+ it { is_expected.to include('+Other data.') }
132
+ end # /context with a single file that does not match
133
+
134
+ context 'with a folder with an extra file' do
135
+ let(:path) { 'sub' }
136
+ before do
137
+ write('sub1.txt', "Subfixture 1.\n")
138
+ write('sub2.txt', "Subfixture 2.\n")
139
+ write('sub3.txt', "Subfixture 3.\n")
140
+ end
141
+ it { is_expected.to include('sub3.txt should not exist') }
142
+ end # /context with a folder with an extra file
143
+
144
+ context 'with a folder with a missing file' do
145
+ let(:path) { 'sub' }
146
+ before do
147
+ write('sub1.txt', "Subfixture 1.\n")
148
+ end
149
+ it { is_expected.to include('sub2.txt is not found') }
150
+ end # /context with a folder with a missing file
151
+
152
+ context 'with a folder that does not match' do
153
+ let(:path) { 'sub' }
154
+ before do
155
+ write('sub1.txt', "Subfixture 1.\n")
156
+ write('sub2.txt', "Subfixture 3.\n")
157
+ end
158
+ it { is_expected.to include('sub2.txt does not match fixture:') }
159
+ it { is_expected.to include('-Subfixture 2.') }
160
+ it { is_expected.to include('+Subfixture 3.') }
161
+ end # /context with a folder that does not match
162
+
163
+ context 'with a file that is a folder' do
164
+ let(:path) { 'sub_nested' }
165
+ before do
166
+ FileUtils.mkdir_p(File.join(temp_path, 'sub_nested.txt'))
167
+ end
168
+ it { is_expected.to include('sub_nested.txt should not be a directory') }
169
+ end # /context with a file that is a folder
170
+
171
+ context 'with a folder that is a file' do
172
+ let(:path) { 'sub_nested' }
173
+ before do
174
+ write('sub_inner', '')
175
+ end
176
+ it { is_expected.to include('sub_inner should be a directory') }
177
+ end # /context with a folder that is a file
178
+ end # /describe #failure_message
179
+
180
+ describe '#differ' do
181
+ subject { described_class.new(nil, nil, nil, nil).send(:differ) }
182
+ # Basically just check that it isn't throwing errors
183
+ it { is_expected.to_not be_nil}
184
+ it { is_expected.to respond_to(:diff) }
185
+ end # /describe #differ
186
+ end
@@ -0,0 +1,117 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe RSpecCommand::Rake do
20
+ include RSpecCommand::Rake
21
+
22
+ describe '#rakefile' do
23
+ rakefile "task 'mytask'\n"
24
+ it { expect(File.exists?(File.join(temp_path, 'Rakefile'))).to eq true }
25
+ end # /describe #rakefile
26
+
27
+ describe '#rake_task' do
28
+ context 'with a simple task' do
29
+ rakefile <<-EOH
30
+ task 'mytask' do
31
+ puts 'complete'
32
+ end
33
+ EOH
34
+ rake_task 'mytask'
35
+ its(:stdout) { is_expected.to eq "complete\n" }
36
+ its(:stderr) { is_expected.to eq '' }
37
+ its(:exitstatus) { is_expected.to eq 0 }
38
+ end # /context with a simple task
39
+
40
+ context 'with an environment variable' do
41
+ rakefile <<-EOH
42
+ task 'mytask' do
43
+ puts ENV['MYVAR']
44
+ end
45
+ EOH
46
+ environment MYVAR: 'envvar'
47
+ rake_task 'mytask'
48
+ its(:stdout) { is_expected.to eq "envvar\n" }
49
+ its(:stderr) { is_expected.to eq '' }
50
+ its(:exitstatus) { is_expected.to eq 0 }
51
+ it { expect(ENV['MYVAR']).to be_nil }
52
+ end # /context with an environment variable
53
+
54
+ context 'with no rakefile' do
55
+ rake_task 'mytask'
56
+ its(:stderr) { is_expected.to include 'No Rakefile found' }
57
+ its(:exitstatus) { is_expected.to eq 1 }
58
+ end # /context with no rakefile
59
+
60
+ context 'with a non-existent task' do
61
+ rakefile ''
62
+ rake_task 'mytask'
63
+ its(:stderr) { is_expected.to include "Don't know how to build task 'mytask'" }
64
+ its(:exitstatus) { is_expected.to eq 1 }
65
+ end # /context with a non-existent task
66
+
67
+ context 'with a task with arguments' do
68
+ rakefile <<-'EOH'
69
+ task 'mytask', %w{arg1 arg2} do |t, args|
70
+ args.with_defaults(arg2: 'default')
71
+ puts "#{args[:arg1]} #{args[:arg2]}"
72
+ end
73
+ EOH
74
+ rake_task 'mytask', 'one'
75
+ its(:stdout) { is_expected.to eq "one default\n" }
76
+ its(:stderr) { is_expected.to eq '' }
77
+ its(:exitstatus) { is_expected.to eq 0 }
78
+ end # /context with a task with arguments
79
+
80
+ context 'with a task that fails' do
81
+ rakefile <<-EOH
82
+ task 'failure' do
83
+ puts 'before'
84
+ raise "OMG"
85
+ puts 'after'
86
+ end
87
+ EOH
88
+ rake_task 'failure'
89
+ its(:stdout) { is_expected.to eq "before\n" }
90
+ its(:stderr) { is_expected.to include "Rakefile:3:in `block in <top (required)>': OMG (RuntimeError)" }
91
+ its(:exitstatus) { is_expected.to eq 1 }
92
+ end # /context with a task that fails
93
+
94
+ context 'with a task that fails with a specific exitstatus' do
95
+ rakefile <<-EOH
96
+ task 'specific_failure' do
97
+ puts 'specific before'
98
+ Kernel.exit(42)
99
+ puts 'specific after'
100
+ end
101
+ EOH
102
+ rake_task 'specific_failure'
103
+ its(:stdout) { is_expected.to eq "specific before\n" }
104
+ its(:stderr) { is_expected.to eq '' }
105
+ its(:exitstatus) { is_expected.to eq 42 }
106
+ end # /context with a task that fails with a specific exitstatus
107
+
108
+ context 'regression test for require-based Rakefiles and multiple tests' do
109
+ file 'mytask.rb', 'task :mytask do puts "complete" end'
110
+ rakefile '$:.unshift(File.dirname(__FILE__)); require "mytask"'
111
+ rake_task 'mytask'
112
+ # Run twice to force the bug.
113
+ its(:stdout) { is_expected.to include "complete\n" }
114
+ its(:stdout) { is_expected.to include "complete\n" }
115
+ end
116
+ end # /describe #rake_task
117
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'rspec'
18
+ require 'simplecov'
19
+
20
+ # Check for coverage stuffs
21
+ formatters = []
22
+ if ENV['CODECLIMATE_REPO_TOKEN']
23
+ require 'codeclimate-test-reporter'
24
+ formatters << CodeClimate::TestReporter::Formatter
25
+ end
26
+
27
+ if ENV['CODECOV_TOKEN']
28
+ require 'codecov'
29
+ formatters << SimpleCov::Formatter::Codecov
30
+ end
31
+
32
+ unless formatters.empty?
33
+ SimpleCov.formatters = formatters
34
+ end
35
+
36
+ SimpleCov.start do
37
+ # Don't get coverage on the test cases themselves.
38
+ add_filter '/spec/'
39
+ add_filter '/test/'
40
+ # Codecov doesn't automatically ignore vendored files.
41
+ add_filter '/vendor/'
42
+ end
43
+
44
+ require 'rspec_command'
45
+
46
+ RSpec.configure do |config|
47
+ # Basic configuraiton
48
+ config.run_all_when_everything_filtered = true
49
+ config.filter_run(:focus)
50
+
51
+ # Run specs in random order to surface order dependencies. If you find an
52
+ # order dependency and want to debug it, you can fix the order by providing
53
+ # the seed, which is printed after each run.
54
+ # --seed 1234
55
+ config.order = 'random'
56
+
57
+ config.include RSpecCommand
58
+ end