@@ -23,121 +23,129 @@ module Glue
23
23
@cucumber_expression_generator = CucumberExpressions ::CucumberExpressionGenerator . new ( @registry )
24
24
end
25
25
26
- def unindented ( snippet )
27
- indent ( snippet . split ( "\n " ) [ 1 ..-2 ] . join ( "\n " ) , -10 )
28
- end
29
-
30
26
describe Snippet ::Regexp do
31
27
let ( :snippet_class ) { described_class }
32
28
let ( :snippet_text ) { snippet . to_s }
33
29
34
30
it 'wraps snippet patterns in parentheses' do
35
31
@step_text = 'A "string" with 4 spaces'
32
+ cucumber_output = <<~CUKE . chomp
33
+ Given(/^A "([^"]*)" with (\\ d+) spaces$/) do |arg1, arg2|
34
+ pending # Write code here that turns the phrase above into concrete actions
35
+ end
36
+ CUKE
36
37
37
- expect ( snippet_text ) . to eq unindented ( %{
38
- Given(/^A "([^"]*)" with (\\ d+) spaces$/) do |arg1, arg2|
39
- pending # Write code here that turns the phrase above into concrete actions
40
- end
41
- } )
38
+ expect ( snippet_text ) . to eq ( cucumber_output )
42
39
end
43
40
44
41
it 'recognises numbers in name and make according regexp' do
45
42
@step_text = 'Cloud 9 yeah'
43
+ cucumber_output = <<~CUKE . chomp
44
+ Given(/^Cloud (\\ d+) yeah$/) do |arg1|
45
+ pending # Write code here that turns the phrase above into concrete actions
46
+ end
47
+ CUKE
46
48
47
- expect ( snippet_text ) . to eq unindented ( %{
48
- Given(/^Cloud (\\ d+) yeah$/) do |arg1|
49
- pending # Write code here that turns the phrase above into concrete actions
50
- end
51
- } )
49
+ expect ( snippet_text ) . to eq ( cucumber_output )
52
50
end
53
51
54
52
it 'recognises a mix of ints, strings and why not a table too' do
55
53
@step_text = 'I have 9 "awesome" cukes in 37 "boxes"'
56
54
@multiline_argument = Core ::Test ::DataTable . new ( [ [ ] ] )
57
-
58
- expect ( snippet_text ) . to eq unindented ( %{
59
- Given(/^I have (\\ d+) "([^"]*)" cukes in (\\ d+) "([^"]*)"$/) do |arg1, arg2, arg3, arg4, table|
60
- # table is a Cucumber::MultilineArgument::DataTable
61
- pending # Write code here that turns the phrase above into concrete actions
62
- end
63
- } )
55
+ cucumber_output = <<~CUKE . chomp
56
+ Given(/^I have (\\ d+) "([^"]*)" cukes in (\\ d+) "([^"]*)"$/) do |arg1, arg2, arg3, arg4, table|
57
+ # table is a Cucumber::MultilineArgument::DataTable
58
+ pending # Write code here that turns the phrase above into concrete actions
59
+ end
60
+ CUKE
61
+
62
+ expect ( snippet_text ) . to eq ( cucumber_output )
64
63
end
65
64
66
65
it 'recognises quotes in name and make according regexp' do
67
66
@step_text = 'A "first" arg'
67
+ cucumber_output = <<~CUKE . chomp
68
+ Given(/^A "([^"]*)" arg$/) do |arg1|
69
+ pending # Write code here that turns the phrase above into concrete actions
70
+ end
71
+ CUKE
68
72
69
- expect ( snippet_text ) . to eq unindented ( %{
70
- Given(/^A "([^"]*)" arg$/) do |arg1|
71
- pending # Write code here that turns the phrase above into concrete actions
72
- end
73
- } )
73
+ expect ( snippet_text ) . to eq ( cucumber_output )
74
74
end
75
75
76
76
it 'recognises several quoted words in name and make according regexp and args' do
77
77
@step_text = 'A "first" and "second" arg'
78
+ cucumber_output = <<~CUKE . chomp
79
+ Given(/^A "([^"]*)" and "([^"]*)" arg$/) do |arg1, arg2|
80
+ pending # Write code here that turns the phrase above into concrete actions
81
+ end
82
+ CUKE
78
83
79
- expect ( snippet_text ) . to eq unindented ( %{
80
- Given(/^A "([^"]*)" and "([^"]*)" arg$/) do |arg1, arg2|
81
- pending # Write code here that turns the phrase above into concrete actions
82
- end
83
- } )
84
+ expect ( snippet_text ) . to eq ( cucumber_output )
84
85
end
85
86
86
87
it 'does not use quote group when there are no quotes' do
87
88
@step_text = 'A first arg'
89
+ cucumber_output = <<~CUKE . chomp
90
+ Given(/^A first arg$/) do
91
+ pending # Write code here that turns the phrase above into concrete actions
92
+ end
93
+ CUKE
88
94
89
- expect ( snippet_text ) . to eq unindented ( %{
90
- Given(/^A first arg$/) do
91
- pending # Write code here that turns the phrase above into concrete actions
92
- end
93
- } )
95
+ expect ( snippet_text ) . to eq ( cucumber_output )
94
96
end
95
97
96
98
it 'is helpful with tables' do
97
99
@step_text = 'A "first" arg'
98
100
@multiline_argument = Core ::Test ::DataTable . new ( [ [ ] ] )
99
-
100
- expect ( snippet_text ) . to eq unindented ( %{
101
- Given(/^A "([^"]*)" arg$/) do |arg1, table|
102
- # table is a Cucumber::MultilineArgument::DataTable
103
- pending # Write code here that turns the phrase above into concrete actions
104
- end
105
- } )
101
+ cucumber_output = <<~CUKE . chomp
102
+ Given(/^A "([^"]*)" arg$/) do |arg1, table|
103
+ # table is a Cucumber::MultilineArgument::DataTable
104
+ pending # Write code here that turns the phrase above into concrete actions
105
+ end
106
+ CUKE
107
+
108
+ expect ( snippet_text ) . to eq ( cucumber_output )
106
109
end
107
110
108
111
it 'is helpful with doc string' do
109
112
@step_text = 'A "first" arg'
110
113
@multiline_argument = MultilineArgument . from ( '' , Core ::Test ::Location . new ( '' ) )
114
+ cucumber_output = <<~CUKE . chomp
115
+ Given(/^A "([^"]*)" arg$/) do |arg1, doc_string|
116
+ pending # Write code here that turns the phrase above into concrete actions
117
+ end
118
+ CUKE
111
119
112
- expect ( snippet_text ) . to eq unindented ( %{
113
- Given(/^A "([^"]*)" arg$/) do |arg1, doc_string|
114
- pending # Write code here that turns the phrase above into concrete actions
115
- end
116
- } )
120
+ expect ( snippet_text ) . to eq ( cucumber_output )
117
121
end
118
122
end
119
123
120
124
describe Snippet ::Classic do
121
125
let ( :snippet_class ) { described_class }
122
126
123
127
it 'renders snippet as unwrapped regular expression' do
124
- expect ( snippet . to_s ) . to eq unindented ( %(
125
- Given /^we have a missing step$/ do
126
- pending # Write code here that turns the phrase above into concrete actions
127
- end
128
- ) )
128
+ cucumber_output = <<~CUKE . chomp
129
+ Given /^we have a missing step$/ do
130
+ pending # Write code here that turns the phrase above into concrete actions
131
+ end
132
+ CUKE
133
+
134
+ expect ( snippet . to_s ) . to eq ( cucumber_output )
129
135
end
130
136
end
131
137
132
138
describe Snippet ::Percent do
133
139
let ( :snippet_class ) { described_class }
134
140
135
141
it 'renders snippet as percent-style regular expression' do
136
- expect ( snippet . to_s ) . to eq unindented ( %(
137
- Given %r{^we have a missing step$} do
138
- pending # Write code here that turns the phrase above into concrete actions
139
- end
140
- ) )
142
+ cucumber_output = <<~CUKE . chomp
143
+ Given %r{^we have a missing step$} do
144
+ pending # Write code here that turns the phrase above into concrete actions
145
+ end
146
+ CUKE
147
+
148
+ expect ( snippet . to_s ) . to eq ( cucumber_output )
141
149
end
142
150
end
143
151
@@ -163,12 +171,14 @@ def unindented(snippet)
163
171
false
164
172
) )
165
173
166
- expect ( snippet . to_s ) . to eq unindented ( %{
167
- Given('I have {float} {cucumis} in my belly') do |float, cucumis|
168
- # Given('I have {float} {veg} in my belly') do |float, veg|
169
- pending # Write code here that turns the phrase above into concrete actions
170
- end
171
- } )
174
+ cucumber_output = <<~CUKE . chomp
175
+ Given('I have {float} {cucumis} in my belly') do |float, cucumis|
176
+ # Given('I have {float} {veg} in my belly') do |float, veg|
177
+ pending # Write code here that turns the phrase above into concrete actions
178
+ end
179
+ CUKE
180
+
181
+ expect ( snippet . to_s ) . to eq ( cucumber_output )
172
182
end
173
183
end
174
184
end
0 commit comments