Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Ruby/RSpec example #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,26 @@ jobs:
with:
paths: javascript-tap/results/**/*.tap
if: always()

# This runs Ruby tests using the RSpec test framework
ruby-rspec:
name: Ruby / RSpec
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1.2'
- name: Run Tests
run: |
bundle install
bundle exec rspec --format RSpec::TAP::Formatters::Flat --out spec/results.tap
working-directory: ruby-rspec
- name: Test Summary
uses: test-summary/action@v1
with:
paths: "ruby-rspec/spec/results.tap"
if: always()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Examples:
* [JavaScript with the mocha test framework](javascript-mocha/)
* [JavaScript with the node-tap test framework](javascript-tap/)
* [.NET](dotnet/)
* [Ruby with RSpec](ruby-rspec/)

For more information about how to configure the test-summary action, visit the [test-summary action](https://github.com/test-summary/action) repository.
1 change: 1 addition & 0 deletions ruby-rspec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spec/*.tap
6 changes: 6 additions & 0 deletions ruby-rspec/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

ruby "3.1.2"

gem "rspec"
gem "rspec-tap-formatters", require: false
34 changes: 34 additions & 0 deletions ruby-rspec/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.5.0)
psych (3.3.2)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rspec-tap-formatters (0.1.0)
psych (>= 2.0, < 4.0)
rspec-core (>= 3.0, < 4.0)

PLATFORMS
arm64-darwin-21

DEPENDENCIES
rspec
rspec-tap-formatters

RUBY VERSION
ruby 3.1.2p20

BUNDLED WITH
2.3.13
58 changes: 58 additions & 0 deletions ruby-rspec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
test-summary example: Ruby with RSpec
==============================================

This produces a test summary for a Ruby project using the RSpec and [rspec-tap-formatters](https://github.com/avmnu-sng/rspec-tap-formatters).

Project Setup
-------------

Add the following line to your Gemfile:

```ruby
gem "rspec-tap-formatters", require: false
````

Ensure it works locally by running:

```bash
bundle exec rspec --format RSpec::TAP::Formatters::Default
```

GitHub Actions Workflow
-----------------------

An example GitHub Actions workflow that builds a Ruby project using RSpec, runs the tests, runs the test-summary action and uploads the test summary markdown as an artifact.

```yaml
name: Build and Test Ruby

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1.2'

- name: Run Tests
run: bundle exec rspec --format RSpec::TAP::Formatters::Flat --out spec/results.tap

- name: Test Summary
uses: test-summary/action@v1
with:
paths: "spec/results.tap"
if: always()
```
54 changes: 54 additions & 0 deletions ruby-rspec/spec/example_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require "rubygems"
require "bundler/setup"
require "rspec/tap/formatters"

RSpec.describe "Example specs" do
it "passes test one" do
result = 21 + 21
expect(result).to eq(42)
end

it "passes test one" do
result = 33 * 3
expect(result).to eq(99)
end

it "passes test three" do
result = "he" + "llo"
expect(result).to eq("hello")
end

it "passes test three" do
result = "world" + ""
expect(result).to eq("world")
end

it "fails test five" do
result = 42 + 1
expect(result).to eq(42)
end

it "fails test six" do
result = 99 - 1
expect(result).to eq(99)
end

it "fails test seven" do
result = "he" + "llo"
expect(result).to eq("world")
end

it "fails test eight" do
result = "world" + ""
expect(result).to eq("hello")
end

it "skips test nine" do
pending
expect(true).to be(false)
end

it "skips test ten" do
skip
end
end