From 1399168a3073368fc9d71b85e35525282fc78b45 Mon Sep 17 00:00:00 2001 From: marschattha Date: Thu, 7 Mar 2024 05:19:00 +0500 Subject: [PATCH] Initial commit --- .github/workflows/main.yml | 39 ++++++++++++++++++++++++++++++++++++++ .gitignore | 11 +++++++++++ .rspec | 3 +++ Gemfile | 10 ++++++++++ Gemfile.lock | 36 +++++++++++++++++++++++++++++++++++ LICENSE.txt | 21 ++++++++++++++++++++ README.md | 31 ++++++++++++++++++++++++++++++ Rakefile | 12 ++++++++++++ bin/console | 15 +++++++++++++++ bin/setup | 8 ++++++++ lib/sample.rb | 25 ++++++++++++++++++++++++ spec/sample_spec.rb | 11 +++++++++++ spec/spec_helper.rb | 17 +++++++++++++++++ 13 files changed, 239 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 lib/sample.rb create mode 100644 spec/sample_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..f93476f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +name: Main +on: + push: + branches: + - main + +permissions: + actions: write + contents: read + +jobs: + build: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - '3.1' + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Run the default task + run: bundle exec rspec + + - uses: qltyai/qlty-action/coverage@main + with: + coverage-token: ${{ secrets.QLTY_COVERAGE_TOKEN }} + file: coverage/.resultset.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b04a8c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..33045cf --- /dev/null +++ b/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + + +gem "rake", "~> 13.0" + +gem "rspec", "~> 3.0" + +gem "simplecov", "~> 0.22.0" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..3c20f76 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,36 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.5.1) + docile (1.4.0) + rake (13.1.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + +PLATFORMS + arm64-darwin-21 + +DEPENDENCIES + rake (~> 13.0) + rspec (~> 3.0) + simplecov (~> 0.22.0) + +BUNDLED WITH + 2.3.17 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..4ec0f78 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Code Climate, Inc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..803fe78 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Qlty Ruby Coverage Example + +[Qlty](https://example.com) is a Code Health Platform with support for code coverage. + +This repository is an example using Qlty to track code coverage for a Ruby project. Coverage data is generated during the [Rspec](https://rspec.info/) run and then uploaded to Qlty. + +This repository uses [Rspec](https://rspec.info/) for testing and [simplecov](https://github.com/simplecov-ruby/simplecov) to generate test coverage. + +## Requirements + +- Ruby 2.7 or above +- Test run with [bundle exec rspec](https://rspec.info/) +- An account on Qlty (free for open source) +- `QLTY_COVERAGE_TOKEN` is set as a GitHub Actions [repository secret](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) + +## Set up + +See [`.github/workflows/main.yml`](./.github/workflows/main.yml) in this repository for a basic configuration. + +## Documentation + +- [Advanced code coverage configuration](https://example.com) +- [Alternative supported CI providers](https://example.com) + +## Help and feedback + +Join the our [Slack Community](https://example.com) for help and to provide feedback that we'll use to improve Qlty. + +## License + +[MIT License](./LICENSE.md) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..1af7d3f --- /dev/null +++ b/bin/console @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "sample" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/lib/sample.rb b/lib/sample.rb new file mode 100644 index 0000000..effb13c --- /dev/null +++ b/lib/sample.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class Sample + class << self + def add(a, b) + a + b + end + + def subtract(a, b) + a - b + end + + def multiply(a, b) + a * b + end + + def main() + puts("Hello, world!"); + + puts("3 + 2 = #{add(3, 2)}"); + puts("5 - 3 = #{subtract(5, 3)}"); + puts("4 * 3 = #{multiply(4, 3)}"); + end + end +end diff --git a/spec/sample_spec.rb b/spec/sample_spec.rb new file mode 100644 index 0000000..953057c --- /dev/null +++ b/spec/sample_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +RSpec.describe Sample do + it "can add two numbers" do + expect(Sample.add(3,4)).to eq(7) + end + + it "can add subtract numbers" do + expect(Sample.subtract(5,2)).to eq(3) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cf9cb8c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true +require 'simplecov' +SimpleCov.start + +require "sample" + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end