Skip to content

Commit 1c7ca58

Browse files
authored
Merge pull request #3318 from masatake/rspec-it
Rspec: handle "it"
2 parents b5cc9e0 + e8daccd commit 1c7ca58

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
A a.rb /^RSpec.describe "A" do$/;" d end:12
22
B b.rb /^RSpec.describe "B" do$/;" d end:2
33
a a.rb /^ describe "a" do$/;" d describe:A end:11
4+
hangs a.rb /^ it "hangs" do$/;" i describe:A.a end:10
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
Order input.rb /^RSpec.describe Order do$/;" describe line:6 language:RSpec end:18
22
with no items input.rb /^ context "with no items" do$/;" context line:7 language:RSpec describe:Order end:11
3+
behaves one way input.rb /^ it "behaves one way" do$/;" it line:8 language:RSpec context:Order.with no items end:10
34
with one item input.rb /^ context "with one item" do$/;" context line:13 language:RSpec describe:Order end:17
5+
behaves another way input.rb /^ it "behaves another way" do$/;" it line:14 language:RSpec context:Order.with one item end:16
46
Calculator input.rb /^RSpec.describe Calculator do$/;" describe line:20 language:RSpec end:26
57
#add input.rb /^ describe '#add' do$/;" describe line:21 language:RSpec describe:Calculator end:25
8+
returns the sum of its arguments input.rb /^ it 'returns the sum of its arguments' do$/;" it line:22 language:RSpec describe:Calculator.#add end:24
69
Core input.rb /^module RSpec::Core$/;" module line:29 language:Ruby module:RSpec end:48
710
ExampleGroup input.rb /^ RSpec.describe ExampleGroup do$/;" describe line:30 language:RSpec end:47
811
when calling `#{method}`, an example group API, from within an example input.rb /^ context "when calling `#{method}`, an example group API, from within an example" do$/;" context line:32 language:RSpec describe:ExampleGroup end:42
12+
tells the user they are in the wrong scope for that API input.rb /^ it "tells the user they are in the wrong scope for that API" do$/;" it line:33 language:RSpec context:ExampleGroup.when calling `#{method}`, an example group API, from within an example end:41
913
Object describing nested example_groups input.rb /^ describe Object, "describing nested example_groups", :little_less_nested => 'yep' do$/;" describe line:45 language:RSpec describe:ExampleGroup end:46

parsers/rspec.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ struct sRSpecSubparser {
6161
typedef enum {
6262
K_DESCRIBE,
6363
K_CONTEXT,
64+
K_IT,
6465
} rspecKind;
6566

6667
static kindDefinition RSpecKinds [] = {
6768
{ true, 'd', "describe", "describes" },
6869
{ true, 'c', "context", "contexts" },
70+
{ true, 'i', "it", "things described with \"it\"" },
6971
};
7072

7173
/*
@@ -141,33 +143,36 @@ static vString *readRest (const unsigned char **cp)
141143
return vstr;
142144
}
143145

146+
struct caseType {
147+
const char *keyword;
148+
rspecKind kind;
149+
};
150+
144151
static int lineNotify (rubySubparser *s, const unsigned char **cp)
145152
{
146-
if (rubyCanMatchKeywordWithAssign (cp, "describe")
147-
|| rubyCanMatchKeywordWithAssign (cp, "RSpec.describe"))
148-
{
149-
vString *vstr = NULL;
150-
rubySkipWhitespace (cp);
151-
vstr = readRest (cp);
152-
if (vstr)
153-
{
154-
int r = makeSimpleRSpecTag (vstr, K_DESCRIBE, s);
155-
vStringDelete (vstr);
156-
return r;
157-
}
158-
}
159-
else if (rubyCanMatchKeywordWithAssign (cp, "context"))
153+
struct caseType caseTypes [] = {
154+
{ "describe", K_DESCRIBE },
155+
{ "RSpec.describe", K_DESCRIBE },
156+
{ "context", K_CONTEXT },
157+
{ "it", K_IT },
158+
};
159+
160+
for (int i = 0; i < ARRAY_SIZE(caseTypes); i++)
160161
{
161-
vString *vstr = NULL;
162-
rubySkipWhitespace (cp);
163-
vstr = readRest (cp);
164-
if (vstr)
162+
if (rubyCanMatchKeywordWithAssign(cp, caseTypes[i].keyword))
165163
{
166-
int r = makeSimpleRSpecTag (vstr, K_CONTEXT, s);
167-
vStringDelete (vstr);
168-
return r;
164+
vString *vstr = NULL;
165+
rubySkipWhitespace (cp);
166+
vstr = readRest (cp);
167+
if (vstr)
168+
{
169+
int r = makeSimpleRSpecTag (vstr, caseTypes[i].kind, s);
170+
vStringDelete (vstr);
171+
return r;
172+
}
169173
}
170174
}
175+
171176
return CORK_NIL;
172177
}
173178

0 commit comments

Comments
 (0)