Skip to content

Commit

Permalink
# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

# This is the commit message #2:

Added rspec tests with code coverage reporting.
  • Loading branch information
jamesiarmes committed May 24, 2023
1 parent 05325d9 commit 18c9211
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 6 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: RuboCop Linter
uses: andrewmcodes/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

spec:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true
- name: Run tests
run: bundle exec rspec
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ vendor
# Ignore import and export files.
./*.csv
./*.json

# Ignore test outputs
coverage
4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--require spec_helper.rb
--color
--format RSpec::Github::Formatter
--format documentation
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: enable
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ gemspec

group :development do
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.12'
gem 'rspec-github', '~> 2.4'
gem 'rubocop', '~> 1.48'
gem 'rubocop-rake', '~> 0.6'
gem 'rubocop-rspec', '~> 2.22'
gem 'simplecov', '~> 0.22'
end
39 changes: 37 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ GEM
ast (2.4.2)
bson (4.15.0)
concurrent-ruby (1.2.2)
down (5.4.0)
diff-lcs (1.5.0)
docile (1.4.0)
down (5.4.1)
addressable (~> 2.8)
faraday (2.7.4)
faraday (2.7.5)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
Expand All @@ -55,6 +57,21 @@ GEM
rake (13.0.6)
regexp_parser (2.8.0)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-github (2.4.0)
rspec-core (~> 3.0)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.51.0)
json (~> 2.3)
parallel (~> 1.10)
Expand All @@ -67,11 +84,25 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.1)
parser (>= 3.2.1.0)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.22.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sequel (5.68.0)
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)
thor (1.2.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand All @@ -87,8 +118,12 @@ PLATFORMS
DEPENDENCIES
cmr-entity-resolution!
rake (~> 13.0)
rspec (~> 3.12)
rspec-github (~> 2.4)
rubocop (~> 1.48)
rubocop-rake (~> 0.6)
rubocop-rspec (~> 2.22)
simplecov (~> 0.22)

BUNDLED WITH
2.4.10
7 changes: 5 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'
require 'rubocop/rake_task'

task default: [:rubocop]
task default: %i[spec rubocop]

RuboCop::RakeTask.new do |task|
RuboCop::RakeTask.new(:rubocop) do |task|
task.requires << 'rubocop'
end

RSpec::Core::RakeTask.new(:spec)
2 changes: 1 addition & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def from_file(path)

def initialize
defaults
yield self
yield self if block_given?
initialize_logger
end

Expand Down
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

if ENV['COVERAGE']
require 'simplecov'

SimpleCov.start do
add_filter '/spec/'

track_files 'lib/**/*.rb'
end
end
29 changes: 29 additions & 0 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative '../../lib/config'

RSpec.describe Config do
describe '#initialize' do
it 'can be initialized without a block' do
expect(described_class.new).to be_a(described_class)
end

it 'can be initialized with a block' do
expect { |probe| described_class.new(&probe) }.to yield_with_args(described_class)
end
end

describe '.from_file' do
subject(:from_file) { described_class.from_file(path) }

let(:path) { File.join(__dir__, '../../config/config.sample.yml') }

it 'can be loaded from a file' do
expect(from_file).to be_a(described_class)
end

it 'loads expected options' do
expect(from_file.sources.first[:type]).to eq('CSV')
end
end
end

0 comments on commit 18c9211

Please sign in to comment.