Skip to content
Permalink
Browse files

Add spec for services

Part of #3
  • Loading branch information...
artofhuman committed Apr 11, 2017
1 parent 6e885a1 commit 357afc1dc8dc468834bc39491f3b1ea417de7559
@@ -35,5 +35,7 @@ group :test do
gem 'rspec'
gem 'rspec-hanami'
gem 'capybara'
gem 'vcr'
gem 'webmock'
gem 'simplecov', require: false
end
@@ -12,6 +12,8 @@ GEM
xpath (~> 2.0)
concurrent-ruby (1.0.5)
connection_pool (2.2.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
docile (1.1.5)
dotenv (2.2.0)
@@ -94,6 +96,7 @@ GEM
hanami-view (1.0.0)
hanami-utils (~> 1.0)
tilt (~> 2.0, >= 2.0.1)
hashdiff (0.3.2)
hashie (3.5.5)
hiredis (0.6.1)
http_router (0.11.2)
@@ -161,6 +164,7 @@ GEM
rspec-support (3.5.0)
rufus-scheduler (3.4.0)
et-orbi (~> 1.0)
safe_yaml (1.0.4)
sass (3.4.23)
sequel (4.45.0)
shotgun (0.9.2)
@@ -193,6 +197,11 @@ GEM
thread_safe (~> 0.1)
url_mount (0.2.1)
rack
vcr (3.0.3)
webmock (2.3.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
xpath (2.0.0)
nokogiri (~> 1.3)

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

RUBY VERSION
ruby 2.4.1p111

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -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
@@ -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
@@ -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
@@ -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
@@ -14,6 +14,13 @@
Hanami::Utils.require!("#{__dir__}/support")

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
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.

0 comments on commit 357afc1

Please sign in to comment.
You can’t perform that action at this time.