Skip to content

Commit

Permalink
Add spec for services
Browse files Browse the repository at this point in the history
Part of #3
  • Loading branch information
artofhuman committed Apr 14, 2017
1 parent 6e885a1 commit 357afc1
Show file tree
Hide file tree
Showing 9 changed files with 7,227 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ group :test do
gem 'rspec' gem 'rspec'
gem 'rspec-hanami' gem 'rspec-hanami'
gem 'capybara' gem 'capybara'
gem 'vcr'
gem 'webmock'
gem 'simplecov', require: false gem 'simplecov', require: false
end end
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ GEM
xpath (~> 2.0) xpath (~> 2.0)
concurrent-ruby (1.0.5) concurrent-ruby (1.0.5)
connection_pool (2.2.1) connection_pool (2.2.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3) diff-lcs (1.3)
docile (1.1.5) docile (1.1.5)
dotenv (2.2.0) dotenv (2.2.0)
Expand Down Expand Up @@ -94,6 +96,7 @@ GEM
hanami-view (1.0.0) hanami-view (1.0.0)
hanami-utils (~> 1.0) hanami-utils (~> 1.0)
tilt (~> 2.0, >= 2.0.1) tilt (~> 2.0, >= 2.0.1)
hashdiff (0.3.2)
hashie (3.5.5) hashie (3.5.5)
hiredis (0.6.1) hiredis (0.6.1)
http_router (0.11.2) http_router (0.11.2)
Expand Down Expand Up @@ -161,6 +164,7 @@ GEM
rspec-support (3.5.0) rspec-support (3.5.0)
rufus-scheduler (3.4.0) rufus-scheduler (3.4.0)
et-orbi (~> 1.0) et-orbi (~> 1.0)
safe_yaml (1.0.4)
sass (3.4.23) sass (3.4.23)
sequel (4.45.0) sequel (4.45.0)
shotgun (0.9.2) shotgun (0.9.2)
Expand Down Expand Up @@ -193,6 +197,11 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
url_mount (0.2.1) url_mount (0.2.1)
rack rack
vcr (3.0.3)
webmock (2.3.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
xpath (2.0.0) xpath (2.0.0)
nokogiri (~> 1.3) nokogiri (~> 1.3)


Expand Down Expand Up @@ -220,6 +229,8 @@ DEPENDENCIES
sidekiq-scheduler sidekiq-scheduler
simplecov simplecov
slim slim
vcr
webmock


RUBY VERSION RUBY VERSION
ruby 2.4.1p111 ruby 2.4.1p111
Expand Down
144 changes: 144 additions & 0 deletions spec/cassettes/commits.yml

Large diffs are not rendered by default.

6,951 changes: 6,951 additions & 0 deletions spec/cassettes/contributors.yml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions spec/contributors/services/add_new_commits_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,26 @@
RSpec.describe AddNewCommits do
let(:contributor_repo) { ContributorRepository.new }
let(:commit_repo) { CommitRepository.new }
let(:project_repo) { ProjectRepository.new }

let!(:contributor) { contributor_repo.create(github: 'artofhuman') }
let!(:project) { project_repo.create(name: 'hanami') }

after do
commit_repo.clear
contributor_repo.clear
end

it 'adds contributor commits to the repo' do
VCR.use_cassette("commits") do
described_class.new.call

commits = commit_repo.all_for_contributor(contributor.id)

expect(commits).not_to be_empty
expect(commits.first.url).to be
expect(commits.first.title).to be
expect(commits.first.project_id).to eq(project.id)
end
end
end
35 changes: 35 additions & 0 deletions spec/contributors/services/add_new_contributors_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,35 @@
RSpec.describe AddNewContributors do
let(:contributors_repo) { ContributorRepository.new }
let(:project_repo) { ProjectRepository.new}

before do
project_repo.create(name: 'contributors')
end

after do
project_repo.clear
contributors_repo.clear
end

it 'adds new contributors to repo' do
VCR.use_cassette("contributors") do
described_class.new.call
end

expect(contributors_repo.find_by_github('jodosha')).to be
expect(contributors_repo.find_by_github('davydovanton')).to be
end

context 'when contributor already in repo' do
before do
contributors_repo.create(github: 'davydovanton')
end

it 'does not adds' do
VCR.use_cassette("contributors") do
expect { described_class.new.call }
.not_to change { contributors_repo.contributors.where(github: 'davydovanton').count }
end
end
end
end
26 changes: 26 additions & 0 deletions spec/contributors/services/all_commits_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,26 @@
RSpec.describe AllCommits do
let(:repo) { ProjectRepository.new }
let(:contributor) { Contributor.new(id: 1, github: 'artofhuman') }

let!(:project) { repo.create(name: 'hanami') }

after do
repo.clear
end

it 'returns contributor commits' do
VCR.use_cassette("commits") do
result = AllCommits.new.call(contributor)

expect(result).not_to be_empty

commit = result.first

expect(commit[:contributor_id]).to eq(contributor.id)
expect(commit[:project_id]).to eq(project.id)
expect(commit[:created_at]).to be_a(Time)
expect(commit[:sha]).to be
expect(commit[:url]).to be
end
end
end
25 changes: 25 additions & 0 deletions spec/contributors/services/all_contributors_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,25 @@
RSpec.describe AllContributors do
let(:repo) { ProjectRepository.new }

before do
repo.create(name: 'contributors')
repo.create(name: 'utils')
end

after do
repo.clear
end

it 'returns array of contributors' do
VCR.use_cassette("contributors") do
result = described_class.new.call

contributors = result.select { |i| %w(davydovanton jodosha).include?(i[:github]) }

expect(contributors.size).to eq(2)
contributors.each do |h|
expect(h[:avatar_url]).to be
end
end
end
end
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
Hanami::Utils.require!("#{__dir__}/support") Hanami::Utils.require!("#{__dir__}/support")


require 'rspec/hanami' require 'rspec/hanami'
require 'vcr'

VCR.configure do |c|
c.hook_into :webmock
c.cassette_library_dir = 'spec/cassettes'
c.default_cassette_options = {record: :new_episodes}
end


# This file was generated by the `rspec --init` command. Conventionally, all # This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
Expand Down

0 comments on commit 357afc1

Please sign in to comment.