Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to token only build creation endpoint #55

Merged
merged 9 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/percy/capybara/anywhere.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Capybara
# end
module Anywhere
def self.run(server, assets_dir, assets_base_url = nil)
unless ENV['PERCY_PROJECT'] && ENV['PERCY_TOKEN']
raise 'Whoops! You need to setup the PERCY_PROJECT and PERCY_TOKEN environment variables.'
if ENV['PERCY_TOKEN'].nil?
raise 'Whoops! You need to setup the PERCY_TOKEN environment variable.'
end

::Capybara.run_server = false
Expand Down
7 changes: 1 addition & 6 deletions lib/percy/capybara/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ def initialize(options = {})

# Check that environment variables required for Percy::Client are set
def required_environment_variables_set?
if !ENV['PERCY_TOKEN'].nil? && ENV['PERCY_PROJECT'].nil?
raise '[percy] It looks like you were trying to enable Percy because PERCY_TOKEN ' \
'is set, but you are missing the PERCY_PROJECT environment variable!'
end

!(ENV['PERCY_PROJECT'].nil? || ENV['PERCY_TOKEN'].nil?)
!!ENV['PERCY_TOKEN']
end

def enabled?
Expand Down
2 changes: 1 addition & 1 deletion lib/percy/capybara/client/builds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize_build(options = {})
Percy.logger.debug { "All build resources loaded (#{Time.now - start}s)" }

rescue_connection_failures do
@current_build = client.create_build(client.config.repo, options)
@current_build = client.create_build(options)
_upload_missing_build_resources(build_resources) unless build_resources.empty?
end
if failed?
Expand Down
2 changes: 1 addition & 1 deletion percy-capybara.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'percy-client', '~> 1.13'
spec.add_dependency 'percy-client', '~> 2.0'
spec.add_dependency 'addressable', '~> 2'

spec.add_development_dependency 'bundler', '~> 1.7'
Expand Down
6 changes: 2 additions & 4 deletions spec/lib/percy/capybara/client/builds_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
RSpec.describe Percy::Capybara::Client::Builds do
let(:enabled) { true }
let(:capybara_client) { Percy::Capybara::Client.new(enabled: enabled) }
let(:builds_api_url) do
"https://percy.io/api/v1/repos/#{Percy::Client::Environment.repo}/builds/"
end
let(:builds_api_url) { "https://percy.io/api/v1/builds/" }

describe '#initialize_build', type: :feature, js: true do
before(:each) { setup_sprockets(capybara_client) }
Expand Down Expand Up @@ -104,7 +102,7 @@
it 'returns the current build' do
mock_double = double('build')
expect(capybara_client.client).to receive(:create_build)
.with(capybara_client.client.config.repo, {})
.with({})
.and_return(mock_double)
.once
capybara_client.initialize_build
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/percy/capybara/client/snapshots_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@

visit '/'
loader # Force evaluation now.
repo = Percy::Client::Environment.repo
stub_request(:post, "https://percy.io/api/v1/repos/#{repo}/builds/")
stub_request(:post, "https://percy.io/api/v1/builds/")
.to_return(status: 201, body: mock_build_response.to_json)
stub_request(:post, 'https://percy.io/api/v1/builds/123/snapshots/')
.to_return(status: 201, body: mock_snapshot_response.to_json)
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/percy/capybara/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
expect(Percy::Capybara::Client.new.enabled?).to eq(false)
end

it 'raises error if PERCY_TOKEN is set but PERCY_PROJECT is not' do
ENV.delete 'PERCY_PROJECT'
expect { Percy::Capybara::Client.new.enabled? }.to raise_error(RuntimeError)
it 'is false if PERCY_TOKEN is not set' do
ENV.delete 'PERCY_TOKEN'
expect(Percy::Capybara::Client.new.enabled?).to eq(false)
end
end

Expand Down
2 changes: 0 additions & 2 deletions spec/support/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ def setup_sprockets(capybara_client)
# Set the environment variables required by Percy::Client
def set_required_env_variables
ENV['PERCY_TOKEN'] = 'aa'
ENV['PERCY_PROJECT'] = 'aa'
end

# Clear the environment variables required by Percy::Client
def clear_percy_env_variables
ENV.delete('PERCY_TOKEN')
ENV.delete('PERCY_PROJECT')
ENV.delete('PERCY_ENABLE')
end
end