-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Zandelok/workflow
(feat): spec coverage, rubocop and github ci
- Loading branch information
Showing
30 changed files
with
529 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
# GitHub recommends pinning actions to a commit SHA. | ||
# To get a newer version, you will need to update the SHA. | ||
# You can also reference a tag or branch, but the action may change without warning. | ||
|
||
name: Ruby | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
rspec: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 | ||
with: | ||
ruby-version: '3.1.0' | ||
bundler-cache: true | ||
|
||
- name: Run tests | ||
run: bundle exec rspec | ||
|
||
rubocop: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 | ||
with: | ||
ruby-version: '3.1.0' | ||
bundler-cache: true | ||
|
||
- name: Rubocop check | ||
run: bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Gemfile.lock | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require: rubocop-rspec | ||
|
||
AllCops: | ||
NewCops: enable | ||
|
||
Style/Documentation: | ||
Enabled: false | ||
|
||
RSpec/NamedSubject: | ||
Enabled: false | ||
|
||
RSpec/NestedGroups: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gem 'faker' | ||
gem 'rspec' | ||
gem 'rubocop' | ||
gem 'rubocop-rspec' | ||
gem 'simplecov' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Array | ||
def count_elements | ||
uniq.map { |el| [el, count(el)] }.to_h | ||
uniq.to_h { |el| [el, count(el)] } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Array | ||
def increase_with_index | ||
map&.with_index { |el, i| el + i } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Array | ||
def select_solo | ||
select { |el| one?(el) } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Array | ||
def split_by_parity | ||
partition(&:even?) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'data_error' | ||
require_relative 'type_error' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../errors/errors' | ||
|
||
module Helpers | ||
class HashtagHelper | ||
def self.make_hashtag(array) | ||
raise Errors::DataError, 'Hashtag should consist of one or more symbols' if array.empty? | ||
|
||
hashtag = "##{array.map(&:to_s).map(&:capitalize).join}" | ||
raise Errors::DataError, 'Hashtag max length 140 symbols' if hashtag.length > 140 | ||
|
||
hashtag | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class String | ||
def camelcase | ||
str = split(/[^a-zA-Z]/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class String | ||
def count_chars | ||
chars.group_by(&:itself).transform_values(&:count) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class String | ||
def palindrome? | ||
downcase.eql?(downcase.reverse) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../lib/array/count_array' | ||
|
||
describe Array do | ||
describe '#count_elements' do | ||
let(:method) { input.count_elements } | ||
|
||
context 'when valid data' do | ||
let(:input) { [1, 1, 2, 3] } | ||
let(:result) { { 1 => 2, 2 => 1, 3 => 1 } } | ||
|
||
it 'expect to return hash' do | ||
expect(method).to eq result | ||
end | ||
end | ||
|
||
context 'when invalid data' do | ||
let(:input) { 'Test' } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../lib/array/increase_array' | ||
|
||
describe Array do | ||
describe '#increase_with_index' do | ||
let(:method) { input.increase_with_index } | ||
|
||
context 'when valid data' do | ||
let(:input) { [1, 1, 2, 3] } | ||
let(:result) { [1, 2, 4, 6] } | ||
|
||
it 'expect to return increased array' do | ||
expect(method).to eq result | ||
end | ||
end | ||
|
||
context 'when invalid data' do | ||
context 'when string passed' do | ||
let(:input) { 'Test' } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
|
||
context 'when array of strings passed' do | ||
let(:input) { %w[Test Test] } | ||
|
||
it 'expect to raise TypeError' do | ||
expect { method }.to raise_error TypeError | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#increase_with_position' do | ||
let(:method) { input.increase_with_position } | ||
|
||
context 'when valid data' do | ||
let(:input) { [1, 1, 2, 3] } | ||
let(:result) { [2, 3, 5, 7] } | ||
|
||
it 'expect to return increased array' do | ||
expect(method).to eq result | ||
end | ||
end | ||
|
||
context 'when invalid data' do | ||
context 'when string passed' do | ||
let(:input) { 'Test' } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
|
||
context 'when array of strings passed' do | ||
let(:input) { %w[Test Test] } | ||
|
||
it 'expect to raise TypeError' do | ||
expect { method }.to raise_error TypeError | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../lib/array/select_array' | ||
|
||
describe Array do | ||
describe '#select_solo' do | ||
let(:method) { input.select_solo } | ||
|
||
context 'when valid data' do | ||
let(:input) { [1, 1, 2, 3] } | ||
let(:result) { [2, 3] } | ||
|
||
it 'expect to return array with solo values' do | ||
expect(method).to eq result | ||
end | ||
end | ||
|
||
context 'when invalid data' do | ||
let(:input) { 'Test' } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../lib/array/split_array' | ||
|
||
describe Array do | ||
describe '#split_by_parity' do | ||
let(:method) { input.split_by_parity } | ||
|
||
context 'when valid data' do | ||
let(:input) { [1, 1, 2, 3] } | ||
let(:result) { [[2], [1, 1, 3]] } | ||
|
||
it 'expect to return splited array' do | ||
expect(method).to eq result | ||
end | ||
end | ||
|
||
context 'when invalid data' do | ||
context 'when string passed' do | ||
let(:input) { 'Test' } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
|
||
context 'when array with subarrays' do | ||
let(:input) { [[1, 2], [2, 3]] } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
|
||
context 'when array of strings passed' do | ||
let(:input) { %w[Test Test] } | ||
|
||
it 'expect to raise NoMethodError' do | ||
expect { method }.to raise_error NoMethodError | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.