Skip to content

Commit

Permalink
Merge 8e5baf2 into 5740a56
Browse files Browse the repository at this point in the history
  • Loading branch information
jmortlock committed Jan 12, 2022
2 parents 5740a56 + 8e5baf2 commit e00e8b3
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.6", "2.7", "3.0"]
ruby: ["2.6", "2.7", "3.0", "3.1"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -14,3 +14,8 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: bundle exec rake
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage/lcov.info
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.0
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## Unreleased

- [PLAT-183] Ruby 3.1, update deprecated rspec syntax, and publish coverage with github action

## 0.2.0

- [TT-8631] Update to build with github actions / ruby 3.0 / rails 6.1
- [TT-1392] Changelog file
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# InputReader

[![Gem Version](https://badge.fury.io/rb/input_reader.svg)](http://badge.fury.io/rb/input_reader)
[![Build Status](https://travis-ci.org/sealink/input_reader.png?branch=master)](https://travis-ci.org/sealink/input_reader)
[![Build Status](https://codeclimate.com/github/sealink/input_reader.png)](https://codeclimate.com/github/sealink/input_reader)
[![Build Status](https://github.com/sealink/input_reader/workflows/Build%20and%20Test/badge.svg?branch=master)](https://github.com/sealink/input_reader/actions)
[![Coverage Status](https://coveralls.io/repos/sealink/input_reader/badge.png)](https://coveralls.io/r/sealink/input_reader)

Reads and parses input and helps build input menus, etc.

Expand Down
2 changes: 0 additions & 2 deletions input_reader.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'coverage-kit'
gem.add_development_dependency 'simplecov-rcov'
gem.add_development_dependency 'guard-rspec'
gem.add_development_dependency 'coveralls'
gem.add_development_dependency 'pry-byebug'
end
2 changes: 1 addition & 1 deletion lib/input_reader/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module InputReader
VERSION = "0.1.0"
VERSION = "0.2.0"
end
47 changes: 23 additions & 24 deletions spec/input_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,77 @@
it 'should read strings' do
expect_output ' '
input '1'
InputReader.get_input.should == '1'
expect(InputReader.get_input).to eq '1'

expect_output 'number '
input '2'
InputReader.get_input(:prompt => 'number').should == '2'
expect(InputReader.get_input(:prompt => 'number')).to eq '2'
end

it 'should read integers' do
input '1'
InputReader.get_int.should == 1
expect(InputReader.get_int).to eq 1
end

it 'should read booleans' do
input 'y'
InputReader.get_boolean.should be true
expect(InputReader.get_boolean).to be true

input 'F'
InputReader.get_boolean.should be false
expect(InputReader.get_boolean).to be false
end

it 'should handle invalid boolean values' do
input 'x'
input 'y'
InputReader.get_boolean.should be true
expect(InputReader.get_boolean).to be true
end

it 'should handle dates' do
input '2012-01-13'
InputReader.get_date.should == Date.new(2012, 1, 13)
expect(InputReader.get_date).to eq Date.new(2012, 1, 13)
end

it 'should handle date times' do
input '2012-01-13 18:45'
InputReader.get_datetime.should == DateTime.new(2012, 1, 13, 18, 45, 0)
expect(InputReader.get_datetime).to eq DateTime.new(2012, 1, 13, 18, 45, 0)
end

it 'should handle arrays' do
input ['1', '2', '3', '']
InputReader.get_array.should == ['1', '2', '3']
expect(InputReader.get_array).to eq ['1', '2', '3']
end

it 'should handle array of ints' do
input ['1', '2', '3', '']
InputReader.get_array_of_ints.should == [1, 2, 3]
expect(InputReader.get_array_of_ints).to eq [1, 2, 3]
end

it 'should handle array of dates' do
input ['2012-01-13', '2012-07-24', '']
InputReader.get_array_of_dates.should == [
expect(InputReader.get_array_of_dates).to eq [
Date.new(2012, 1, 13),
Date.new(2012, 7, 24)
]
end

it 'should handle array of date times' do
input ['2012-01-13 14:45', '2012-07-24 19:59', '']
InputReader.get_array_of_datetimes.should == [
expect(InputReader.get_array_of_datetimes).to eq [
DateTime.new(2012, 1, 13, 14, 45, 0),
DateTime.new(2012, 7, 24, 19, 59)
]
end

it 'should allow selecting between choices' do
input '2'
InputReader.select_item(['Alpha', 'Beta', 'Gamma']).should == 'Beta'
expect(InputReader.select_item(['Alpha', 'Beta', 'Gamma'])).to eq 'Beta'
end

it 'should return nil if no choice is selected' do
input ''
InputReader.select_item(['Alpha', 'Beta', 'Gamma'],
:allow_blank => true).should == nil
expect(InputReader.select_item(['Alpha', 'Beta', 'Gamma'],
:allow_blank => true)).to eq nil
end

it 'should handle selecting between multiple choices' do
Expand All @@ -86,8 +86,7 @@
double(:name => 'Gamma')
]
input '1,3'
InputReader.select_items(objects, :selection_attribute => :name).should ==
[objects[0], objects[2]]
expect(InputReader.select_items(objects, :selection_attribute => :name)).to eq ([objects[0], objects[2]])
end

it 'should return an empty array if no choices are selected' do
Expand All @@ -97,38 +96,38 @@
double(:name => 'Gamma')
]
input ''
InputReader.select_items(objects,
expect(InputReader.select_items(objects,
:selection_attribute => :name,
:allow_blank => true).should == []
:allow_blank => true)).to eq []
end

it 'should allow confirming' do
input 'N'
block = lambda{ }
block.should_not_receive(:call)
expect(block).not_to receive(:call)
InputReader.confirmation_required do
block.call
end

input 'Y'
block = lambda{ }
block.should_receive(:call)
expect(block).to receive(:call)
InputReader.confirmation_required do
block.call
end

input 'X'
block = lambda{ }
block.should_not_receive(:call)
expect(block).not_to receive(:call)
InputReader.confirmation_required do
block.call
end
end

it 'should validate unparsed input' do
input ['1', '2']
InputReader.get_int(
expect(InputReader.get_int(
:parsed_input_validators => [{:validator => :even?}]
).should == 2
)).to eq 2
end
end
7 changes: 3 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus

Expand All @@ -19,14 +18,14 @@
require 'support/coverage_loader'

def expect_output(output)
$stdout.should_receive(:print).with(output)
expect($stdout).to receive(:print).with(output)
end

def input(input)
if input.is_a?(String)
$stdin.should_receive(:gets).once.and_return(input)
expect($stdin).to receive(:gets).once.and_return(input)
elsif input.is_a?(Array)
$stdin.should_receive(:gets).exactly(input.size).times.and_return(*input)
expect($stdin).to receive(:gets).exactly(input.size).times.and_return(*input)
else
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/support/coverage_loader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'simplecov-rcov'
require 'coveralls'
require 'coverage/kit'

Coverage::Kit.setup(minimum_coverage: 94.65)

0 comments on commit e00e8b3

Please sign in to comment.