Skip to content

Commit

Permalink
Adds code coverage tracking
Browse files Browse the repository at this point in the history
* also minor code tweaks
* minitest rake task replaced with rake testtask (minitest's task didn't work with simplecov for some reason)
  • Loading branch information
svyatov committed Mar 3, 2024
1 parent f3ab4df commit 0c5d34c
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 184 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:

env:
ACTIONVIEW_VERSION: ${{ matrix.actionview_version }}
COVERAGE: true

steps:
- uses: actions/checkout@v4
Expand All @@ -27,3 +28,9 @@ jobs:

- run: bundle exec rake
continue-on-error: ${{ matrix.ruby_version == 'ruby-head' }}

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: svyatov/clsx-rails
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ gem 'benchmark-ips', '~> 2.13'
gem 'minitest', '~> 5.22'
gem 'rake', '~> 13.0'
gem 'rubocop', '~> 1.21'

gem 'simplecov', require: false
gem 'simplecov-cobertura', require: false
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GEM
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crass (1.0.6)
docile (1.4.0)
drb (2.2.1)
erubi (1.12.0)
i18n (1.14.1)
Expand Down Expand Up @@ -93,6 +94,15 @@ GEM
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-cobertura (2.1.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand All @@ -109,6 +119,8 @@ DEPENDENCIES
minitest (~> 5.22)
rake (~> 13.0)
rubocop (~> 1.21)
simplecov
simplecov-cobertura

BUNDLED WITH
2.5.6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# clsx-rails [![CI](https://github.com/svyatov/clsx-rails/workflows/CI/badge.svg)](https://github.com/svyatov/clsx-rails/actions?query=workflow%3ACI) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
# clsx-rails [![Gem Version](https://img.shields.io/gem/v/clsx-rails)](https://rubygems.org/gems/clsx-rails) ![Codecov](https://img.shields.io/codecov/c/github/svyatov/clsx-rails) [![CI](https://github.com/svyatov/clsx-rails/workflows/CI/badge.svg)](https://github.com/svyatov/clsx-rails/actions?query=workflow%3ACI) [![GitHub License](https://img.shields.io/github/license/svyatov/clsx-rails)](LICENSE.txt)

> A tiny Rails view helper for constructing CSS class strings conditionally.
Expand Down
11 changes: 7 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'minitest/test_task'

Minitest::TestTask.create

require 'rake/testtask'
require 'rubocop/rake_task'

RuboCop::RakeTask.new

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

task default: %i[rubocop test]
1 change: 1 addition & 0 deletions lib/clsx-rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'active_support'
require 'action_view'

require_relative 'clsx/version'
require_relative 'clsx/helper'
Expand Down
1 change: 0 additions & 1 deletion lib/clsx/helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'set'
require 'action_view'

# :nodoc:
module Clsx
Expand Down
46 changes: 24 additions & 22 deletions test/clsx/helper_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@

require 'test_helper'

class TestClsxHelperIntegration < ActionView::TestCase
tests Clsx::Helper
module Clsx
class HelperIntegrationTest < ActionView::TestCase
tests Helper

include RenderERBUtils
include RenderERBUtils

def test_clsx_works
expected = %(<div class="clsx-works"></div>)
actual = tag.div class: clsx('clsx-works')
def test_clsx_works
expected = %(<div class="clsx-works"></div>)
actual = tag.div class: clsx('clsx-works')

assert_dom_equal expected, actual
end
assert_dom_equal expected, actual
end

def test_cn_alias_works
expected = %(<div class="cn-works"></div>)
actual = tag.div class: cn('cn-works')
def test_cn_alias_works
expected = %(<div class="cn-works"></div>)
actual = tag.div class: cn('cn-works')

assert_dom_equal expected, actual
end
assert_dom_equal expected, actual
end

def test_clsx_return_does_not_render_empty_class_when_used_with_tag_helpers
expected = %(<div></div>)
actual = tag.div class: clsx('')
def test_clsx_return_does_not_render_empty_class_when_used_with_tag_helpers
expected = %(<div></div>)
actual = tag.div class: clsx('')

assert_dom_equal expected, actual
end
assert_dom_equal expected, actual
end

def test_clsx_return_leaves_empty_class_when_used_with_erb
expected = %(<div class=""></div>)
actual = render_erb %(<div class="<%= clsx('') %>"></div>)
def test_clsx_return_leaves_empty_class_when_used_with_erb
expected = %(<div class=""></div>)
actual = render_erb %(<div class="<%= clsx('') %>"></div>)

assert_dom_equal expected, actual
assert_dom_equal expected, actual
end
end
end
Loading

0 comments on commit 0c5d34c

Please sign in to comment.