From bf69ada5e299a5375dbb3183fbb1a23814c56fe8 Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Tue, 17 May 2022 11:20:25 -0400 Subject: [PATCH] Add a Ruby/RSpec example --- .github/workflows/examples.yml | 23 +++++++++++++ README.md | 1 + ruby-rspec/.gitignore | 1 + ruby-rspec/Gemfile | 6 ++++ ruby-rspec/Gemfile.lock | 34 +++++++++++++++++++ ruby-rspec/README.md | 58 +++++++++++++++++++++++++++++++++ ruby-rspec/spec/example_spec.rb | 54 ++++++++++++++++++++++++++++++ 7 files changed, 177 insertions(+) create mode 100644 ruby-rspec/.gitignore create mode 100644 ruby-rspec/Gemfile create mode 100644 ruby-rspec/Gemfile.lock create mode 100644 ruby-rspec/README.md create mode 100644 ruby-rspec/spec/example_spec.rb diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 08d92bf..e19827b 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -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() diff --git a/README.md b/README.md index ac4fa8c..0a5b88c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/ruby-rspec/.gitignore b/ruby-rspec/.gitignore new file mode 100644 index 0000000..bb2a3cf --- /dev/null +++ b/ruby-rspec/.gitignore @@ -0,0 +1 @@ +spec/*.tap diff --git a/ruby-rspec/Gemfile b/ruby-rspec/Gemfile new file mode 100644 index 0000000..3b1d287 --- /dev/null +++ b/ruby-rspec/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +ruby "3.1.2" + +gem "rspec" +gem "rspec-tap-formatters", require: false diff --git a/ruby-rspec/Gemfile.lock b/ruby-rspec/Gemfile.lock new file mode 100644 index 0000000..8d6bb8f --- /dev/null +++ b/ruby-rspec/Gemfile.lock @@ -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 diff --git a/ruby-rspec/README.md b/ruby-rspec/README.md new file mode 100644 index 0000000..02644ca --- /dev/null +++ b/ruby-rspec/README.md @@ -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() +``` diff --git a/ruby-rspec/spec/example_spec.rb b/ruby-rspec/spec/example_spec.rb new file mode 100644 index 0000000..2045614 --- /dev/null +++ b/ruby-rspec/spec/example_spec.rb @@ -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