spec_selector 0.1.4 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,213 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'SpecSelectorUtil::Format' do
4
- include_context 'shared'
5
-
6
- describe '#fetch_examples' do
7
- context 'when argument is an example' do
8
- let(:example) { build(:example) }
9
-
10
- it 'returns an array containing only the argument' do
11
- expect(spec_selector.fetch_examples(example)).to eq([example])
12
- end
13
- end
14
-
15
- context 'when argument is an example group with no subgroups' do
16
- before { ivar_set(:@map, mixed_map) }
17
-
18
- it 'returns an array of the examples that belong to the example group' do
19
- expect(spec_selector.fetch_examples(pass_group)).to eq(pass_group.examples)
20
- end
21
- end
22
-
23
- context 'when argument is an example group with subgroups' do
24
- before { ivar_set(:@map, deep_map) }
25
-
26
- it 'returns an array of all descendent examples of the example group' do
27
- expect(spec_selector.fetch_examples(fail_parent_group)).to eq(fail_subgroup.examples)
28
- end
29
- end
30
- end
31
-
32
- describe '#format_list_item' do
33
- context 'when argument is a currently selected list item' do
34
- before { ivars_set(:@list => deep_map[:top_level], :@selected => pass_parent_group, :@map => deep_map) }
35
-
36
- it 'prints the argument description in highlighted text' do
37
- spec_selector.format_list_item(pass_parent_group)
38
- expect(output).to eq("\e[1;7mpass_parent_group\e[0m\n")
39
- end
40
- end
41
-
42
- context 'when argument is non-selected passing example' do
43
- before { ivar_set(:@map, deep_map) }
44
-
45
- it 'prints the argument description in green text' do
46
- spec_selector.format_list_item(passing_example)
47
- expect(output).to eq("\e[1;32mpassing_example\e[0m\n")
48
- end
49
- end
50
-
51
- context 'when argument is non-selected example group whose descendent examples all pass' do
52
- before { ivar_set(:@map, mixed_map) }
53
-
54
- it 'prints the argument description in green text' do
55
- spec_selector.format_list_item(pass_group)
56
- expect(output).to eq("\e[1;32mpass_group\e[0m\n")
57
- end
58
- end
59
-
60
- context 'when argument is non-selected failed example' do
61
- it 'prints the argument description in red text' do
62
- spec_selector.format_list_item(failed_example)
63
- expect(output).to eq("\e[1;31mfailed_example\e[0m\n")
64
- end
65
- end
66
-
67
- context 'when argument is non-selected example group with at least one failed descendent example' do
68
- before { ivar_set(:@map, deep_map) }
69
-
70
- it 'prints the argument description in red text' do
71
- spec_selector.format_list_item(fail_parent_group)
72
- expect(output).to eq("\e[1;31mfail_parent_group\e[0m\n")
73
- end
74
- end
75
-
76
- context 'when argument is a pending example' do
77
- it 'prints the argument description in yellow text' do
78
- spec_selector.format_list_item(pending_example)
79
- expect(output).to eq("\e[1;33mpending_example\e[0m\n")
80
- end
81
- end
82
-
83
- context 'when argument is non-selected example group with at least one pending and no failed descendent examples' do
84
- before { ivar_set(:@map, pending_map) }
85
-
86
- it 'prints the argument description in yellow text' do
87
- spec_selector.format_list_item(pending_group)
88
- expect(output).to eq("\e[1;33mpending_group\e[0m\n")
89
- end
90
- end
91
-
92
- context 'when argument is included in filter' do
93
- let(:example) { build(:example, metadata: { include: true, description: 'the example' }) }
94
-
95
- it 'prints the argument description with a check mark' do
96
- spec_selector.format_list_item(example)
97
- expect(output).to eq("\e[1;32mthe example\e[0m √\n")
98
- end
99
- end
100
- end
101
-
102
- describe '#pass_count' do
103
- before { ivar_set(:@pass_count, 30) }
104
-
105
- it 'prints the current number of passing examples in green text' do
106
- spec_selector.pass_count
107
- expect(output).to eq("\e[1;32mPASS: 30\e[0m\n")
108
- end
109
- end
110
-
111
- describe '#pending_count' do
112
- before { ivar_set(:@pending_count, 10) }
113
-
114
- it 'prints the current number of pending examples' do
115
- spec_selector.pending_count
116
- expect(output).to eq("\e[1;33mPENDING: 10\e[0m\n")
117
- end
118
- end
119
-
120
- describe '#fail_count' do
121
- before { ivar_set(:@fail_count, 20) }
122
-
123
- it 'prints the current number of failed examples' do
124
- spec_selector.fail_count
125
- expect(output).to eq("\e[1;31mFAIL: 20\e[0m\n")
126
- end
127
- end
128
-
129
- describe '#highlight' do
130
- before { ivar_set(:@selected, passing_example) }
131
-
132
- it 'prints the argument in highlighted text' do
133
- spec_selector.highlight(passing_example.description)
134
- expect(output).to eq("\e[1;7mpassing_example\e[0m\n")
135
- end
136
-
137
- context 'when argument is included in filter' do
138
- it 'prints the argument with a check mark' do
139
- spec_selector.highlight(passing_example.description, true)
140
- expect(output).to eq("\e[1;7mpassing_example √\e[0m\n")
141
- end
142
- end
143
- end
144
-
145
- describe '#lineage' do
146
- it 'recursively prepends descriptions of ancestor example groups to description of argument' do
147
- expect(spec_selector.lineage(pass_subgroup.metadata)).to eq('pass_parent_group -> pass_subgroup')
148
- end
149
- end
150
-
151
- describe '#format_example' do
152
- it 'prints description of selected example' do
153
- ivar_set(:@selected, passing_example)
154
- spec_selector.format_example(:passed, nil)
155
- expect(output).to match(/passing_example/)
156
- end
157
-
158
- context 'when selected example is passing' do
159
- it 'prints "PASSED" in green text' do
160
- ivar_set(:@selected, passing_example)
161
- spec_selector.format_example(:passed, nil)
162
- expect(output).to include("\e[1;32mPASSED\e[0m")
163
- end
164
- end
165
-
166
- context 'when selected example is pending or failed' do
167
- let(:notification) { build(:failed_example_notification) }
168
-
169
- it 'prints example result summary' do
170
- ivar_set(:@selector_index, 0)
171
- spec_selector.format_example(:failed, notification)
172
- expect(output).to include('failed example')
173
- end
174
- end
175
- end
176
-
177
- describe '#print_nonpassing_example' do
178
- context 'when selected example is failed' do
179
- let(:notification) { build(:failed_example_notification) }
180
-
181
- it 'prints failure summary of selected example' do
182
- ivar_set(:@selector_index, 0)
183
- spec_selector.print_nonpassing_example(notification)
184
- expect(output).to include('failed example')
185
- end
186
- end
187
-
188
- context 'when selected example is pending' do
189
- let(:notification) { build(:skipped_example_notification) }
190
-
191
- it 'prints pending summary of selected example' do
192
- ivar_set(:@selector_index, 0)
193
- spec_selector.print_nonpassing_example(notification)
194
- expect(output).to include('pending example')
195
- end
196
- end
197
- end
198
-
199
- describe '#print_passing_example' do
200
- before do
201
- ivar_set(:@selected, passing_example)
202
- spec_selector.print_passing_example
203
- end
204
-
205
- it 'prints description of selected example' do
206
- expect(output).to include('passing_example')
207
- end
208
-
209
- it 'prints "PASSED"' do
210
- expect(output).to include('PASSED')
211
- end
212
- end
213
- end
@@ -1,222 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe 'SpecSelectorUtil::Helpers' do
4
- include_context 'shared'
5
-
6
- describe '#all_passing?' do
7
- context 'when all examples have passed' do
8
- before { ivars_set({ :@pass_count => 10, :@fail_count => 0, :@pending_count => 0 }) }
9
-
10
- it 'returns true' do
11
- expect(spec_selector.all_passing?).to be true
12
- end
13
- end
14
-
15
- context 'when not all examples have passed' do
16
- before { ivars_set({ :@pass_count => 5, :@fail_count => 5, :@pending_count => 5 }) }
17
-
18
- it 'returns false' do
19
- expect(spec_selector.all_passing?).to be false
20
- end
21
- end
22
- end
23
-
24
- describe '#none_passing?' do
25
- context 'when no examples have passed' do
26
- before { ivars_set({ :@pass_count => 0, :@fail_count => 5, :@pending_count => 5 }) }
27
-
28
- it 'returns true' do
29
- expect(spec_selector.none_passing?).to be true
30
- end
31
- end
32
-
33
- context 'when at least one example has passed' do
34
- before { ivars_set({ :@pass_count => 1, :@fail_count => 4, :@pending_count => 5 }) }
35
-
36
- it 'returns false' do
37
- expect(spec_selector.none_passing?).to be false
38
- end
39
- end
40
- end
41
-
42
- describe '#all_passed?' do
43
- context 'when every example in argument array has passed' do
44
- let(:examples) { pass_group.examples }
45
-
46
- it 'returns true' do
47
- expect(spec_selector.all_passed?(examples)).to be true
48
- end
49
- end
50
-
51
- context 'when at least one example in argument array did not pass' do
52
- let(:examples) { mixed_result_group.examples }
53
-
54
- it 'returns false' do
55
- expect(spec_selector.all_passed?(examples)).to be false
56
- end
57
- end
58
- end
59
-
60
- describe '#any_failed?' do
61
- context 'when at least one example in argument array has failed' do
62
- let(:examples) { fail_group.examples }
63
-
64
- it 'returns true' do
65
- expect(spec_selector.any_failed?(examples)).to be true
66
- end
67
- end
68
-
69
- context 'when no examples in argument array have failed' do
70
- let(:examples) { pass_group.examples }
71
-
72
- it 'returns false' do
73
- expect(spec_selector.any_failed?(examples)).to be false
74
- end
75
- end
76
- end
77
-
78
- describe '#any_pending?' do
79
- context 'when at least one example has pending status' do
80
- let(:examples) { mixed_result_group.examples }
81
-
82
- it 'returns true' do
83
- expect(spec_selector.any_pending?(examples)).to be true
84
- end
85
- end
86
-
87
- context 'when no examples have pending status' do
88
- let(:examples) { fail_group.examples }
89
-
90
- it 'returns false' do
91
- expect(spec_selector.any_pending?(examples)).to be false
92
- end
93
- end
94
- end
95
-
96
- describe '#example?' do
97
- context 'when argument is an instance of RSpec::Core::Example' do
98
- let(:example) { build(:example) }
99
-
100
- it 'returns true' do
101
- expect(spec_selector.example?(example)).to be true
102
- end
103
- end
104
-
105
- context 'when argument is not an instance of RSpec::Core::Example' do
106
- let(:non_example) { build(:example_group) }
107
-
108
- it 'returns false' do
109
- expect(spec_selector.example?(non_example)).to be false
110
- end
111
- end
112
- end
113
-
114
- describe '#status' do
115
- it 'returns the execution result status of example' do
116
- expect(spec_selector.status(passing_example)).to eq(:passed)
117
- end
118
- end
119
-
120
- describe '#description_mode?' do
121
- context 'when @filter_mode is set to :description' do
122
- before { spec_selector.ivar_set(:@filter_mode, :description) }
123
-
124
- it 'returns true' do
125
- expect(spec_selector.description_mode?).to be true
126
- end
127
- end
128
-
129
- context 'when @filter_mode is not set to :description' do
130
- before { spec_selector.ivar_set(:@filter_mode, :location) }
131
-
132
- it 'returns false' do
133
- expect(spec_selector.description_mode?).to be false
134
- end
135
- end
136
- end
137
-
138
- describe '#location_mode?' do
139
- context 'when @filter_mode is set to :location' do
140
- before { spec_selector.ivar_set(:@filter_mode, :location) }
141
-
142
- it 'returns true' do
143
- expect(spec_selector.location_mode?).to be true
144
- end
145
- end
146
-
147
- context 'when @filter_mode is not set to :location' do
148
- before { spec_selector.ivar_set(:@filter_mode, :description) }
149
-
150
- it 'returns false' do
151
- expect(spec_selector.location_mode?).to be false
152
- end
153
- end
154
- end
155
-
156
- describe '#empty_line' do
157
- it 'prints an newline character' do
158
- spec_selector.empty_line
159
- expect(output).to eq("\n")
160
- end
161
- end
162
-
163
- describe '#top_level?' do
164
- context 'when current list is a top-level list' do
165
- before { ivars_set(:@active_map => mixed_map, :@list => mixed_map[:top_level]) }
166
-
167
- it 'returns true' do
168
- expect(spec_selector.top_level?).to be true
169
- end
170
- end
171
-
172
- context 'when current list is not a top-level list' do
173
- before { ivars_set(:@active_map => mixed_map, :@list => mixed_map[fail_group.metadata[:block]]) }
174
-
175
- it 'returns false' do
176
- expect(spec_selector.top_level?).to be false
177
- end
178
- end
179
- end
180
-
181
- describe '#filter_view?' do
182
- context 'when current list is inclusion filter' do
183
- before { ivars_set(:@inclusion_filter => fail_group.examples, :@list => fail_group.examples) }
184
-
185
- it 'returns true' do
186
- expect(spec_selector.filter_view?).to be true
187
- end
188
- end
189
-
190
- context 'when current list is not inclusion filter' do
191
- before { ivars_set(:@inclusion_filter => fail_group.examples, :@list => pass_group.examples) }
192
-
193
- it 'returns false' do
194
- expect(spec_selector.filter_view?).to be false
195
- end
196
- end
197
- end
198
-
199
- describe '#current_path' do
200
- it 'returns the absolute path to directory that contains the current file' do
201
- expect(spec_selector.current_path).to match(%r{spec_selector/lib/spec_selector$})
202
- end
203
- end
204
-
205
- describe '#one_liner?' do
206
- context 'when the argument is an example written in descriptionless (one-liner) syntax' do
207
- let(:example) { build(:example, metadata: { description_args: [] }) }
208
-
209
- it 'returns true' do
210
- expect(spec_selector.one_liner?(example)).to be true
211
- end
212
- end
213
-
214
- context 'when the argument is a described example' do
215
- let(:example) { build(:example, metadata: { description_args: ['is a described example'] }) }
216
-
217
- it 'returns false' do
218
- expect(spec_selector.one_liner?(example)).to be false
219
- end
220
- end
221
- end
222
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe SpecSelectorUtil::Initialize do
4
- # the subject calls #initialze_all during initialization, which calls
5
- # all of the other methods in this block.
6
- subject(:spec_selector) { SpecSelector.new(StringIO.new) }
7
-
8
- describe '#init_example_store' do
9
- it 'initializes @failed to an empty array' do
10
- expect(spec_selector.ivar(:@failed)).to eq([])
11
- end
12
-
13
- it 'initializes @passed to an empty array' do
14
- expect(spec_selector.ivar(:@passed)).to eq([])
15
- end
16
-
17
- it 'initializes @pending to an empty array' do
18
- expect(spec_selector.ivar(:@pending)).to eq([])
19
- end
20
- end
21
-
22
- describe '#init_summaries' do
23
- it 'initializes @failure_summaries to an empty hash' do
24
- expect(spec_selector.ivar(:@failure_summaries)).to eq({})
25
- end
26
-
27
- it 'initializes @pending_summaries to an empty hash' do
28
- expect(spec_selector.ivar(:@pending_summaries)).to eq({})
29
- end
30
- end
31
-
32
- describe '#init_counters' do
33
- it 'initializes @pass_count to zero' do
34
- expect(spec_selector.ivar(:@pass_count)).to eq(0)
35
- end
36
-
37
- it 'initializes @fail_count to zero' do
38
- expect(spec_selector.ivar(:@fail_count)).to eq(0)
39
- end
40
-
41
- it 'initializes @pending_count to zero' do
42
- expect(spec_selector.ivar(:@pending_count)).to eq(0)
43
- end
44
- end
45
-
46
- describe '#init_pass_inclusion' do
47
- it 'initializes @exclude_passing to false' do
48
- expect(spec_selector.ivar(:@exclude_passing)).to eq(false)
49
- end
50
- end
51
-
52
- describe '#init_map' do
53
- let(:map) { spec_selector.ivar(:@map) }
54
-
55
- it 'initializes @groups to an empty hash' do
56
- expect(spec_selector.ivar(:@groups)).to eq({})
57
- end
58
-
59
- it 'initializes @map to an empty hash' do
60
- expect(map).to eq({})
61
- end
62
-
63
- it 'initializes @active_map to @map' do
64
- expect(spec_selector.ivar(:@active_map)).to eq(map)
65
- end
66
-
67
- it 'initializes @list to nil' do
68
- expect(spec_selector.ivar(:@list)).to be_nil
69
- end
70
- end
71
-
72
- describe '#init_selector' do
73
- it 'initializes @selected to nil' do
74
- expect(spec_selector.ivar(:@selected)).to be_nil
75
- end
76
-
77
- it 'initialzes @selector_index to zero' do
78
- expect(spec_selector.ivar(:@selector_index)).to eq(0)
79
- end
80
- end
81
-
82
- # #initialize_all calls the above methods and initializes the
83
- # instance variables tested below.
84
- describe '#initialize_all' do
85
- it 'initializes @messages to an empty array' do
86
- expect(spec_selector.ivar(:@messages)).to eq([])
87
- end
88
-
89
- it 'initializes @instructions to false' do
90
- expect(spec_selector.ivar(:@instructions)).to eq(false)
91
- end
92
- end
93
- end