Commit ba25361
authored
fix(ruby): Add more RSpec test methods (#227)
Add missing RSpec test methods like `its`, `specify`, `example`,
`feature`, `scenario`. Also, add support for focused methods like
`fdescribe`, `fit` and so on.
Here is the test file (Claude-generated):
```ruby
# Test file for RSpec keywords in runnables and outline queries
RSpec.describe "Standard RSpec keywords" do
context "when using basic keywords" do
it "supports it keyword" do
expect(true).to be true
end
example "supports example keyword" do
expect(true).to be true
end
specify "supports specify keyword" do
expect(true).to be true
end
end
context "when using one-liner syntax" do
subject { [ 1, 2, 3 ] }
it { is_expected.to include(1) }
its(:size) { is_expected.to eq(3) }
end
end
# Focused examples for running specific tests
RSpec.fdescribe "Focused describe block" do
fcontext "focused context" do
fit "focused it example" do
expect(1 + 1).to eq(2)
end
fexample "focused example keyword" do
expect(true).to be true
end
focus "focused with focus keyword" do
expect(true).to be true
end
end
end
# Skipped/pending examples
RSpec.xdescribe "Skipped describe block" do
xcontext "skipped context" do
xit "skipped it example" do
raise "This should not run"
end
xexample "skipped example" do
raise "This should not run"
end
xspecify "skipped specify" do
raise "This should not run"
end
skip "explicitly skipped" do
raise "This should not run"
end
pending "marked as pending" do
raise "This is pending"
end
end
end
# Shared examples
RSpec.shared_examples "a collection" do
it "has a size" do
expect(subject.size).to be >= 0
end
it "is enumerable" do
expect(subject).to respond_to(:each)
end
end
RSpec.describe Array do
subject { [ 1, 2, 3 ] }
it_behaves_like "a collection"
it_should_behave_like "a collection"
include_examples "a collection"
end
RSpec.shared_context "with setup data" do
let(:user) { double("User") }
let(:admin) { double("Admin") }
end
RSpec.describe "Using shared context" do
include_context "with setup data"
it "has access to shared data" do
expect(user).not_to be_nil
end
end
# Capybara/feature specs
RSpec.feature "User authentication" do
scenario "user logs in successfully" do
expect(true).to be true
end
scenario "user logs out" do
expect(true).to be true
end
end
# Nested describe blocks
RSpec.describe "Calculator" do
describe "#add" do
context "with positive numbers" do
it "returns the sum" do
expect(1 + 1).to eq(2)
end
end
context "with negative numbers" do
example "returns the sum" do
expect(-1 + -1).to eq(-2)
end
end
end
describe "#subtract" do
specify "subtracts two numbers" do
expect(5 - 3).to eq(2)
end
end
end
```
Some screeshots:
<img width="1100" height="1226" alt="CleanShot 2026-01-05 at 15 35
30@2x"
src="https://github.com/user-attachments/assets/8cd94097-2bec-4ab4-94f5-397e227463a8"
/>
<img width="1100" height="824" alt="CleanShot 2026-01-05 at 15 35 26@2x"
src="https://github.com/user-attachments/assets/8a3d0b8c-5a28-4404-a164-d9f94af5914d"
/>
<img width="1084" height="1136" alt="CleanShot 2026-01-05 at 15 35
20@2x"
src="https://github.com/user-attachments/assets/9c83db73-b2b1-49e8-a4ce-f93771a1ff93"
/>
Skipped/pending test examples are visible in the outline panel but they
are not runnable:
<img width="1798" height="980" alt="CleanShot 2026-01-05 at 15 35 43@2x"
src="https://github.com/user-attachments/assets/ee443fa0-cd96-4b3f-b4fa-b8d68ab670b1"
/>
Fixes #2251 parent a7f9a27 commit ba25361
2 files changed
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
0 commit comments