Start testing scenarios with the plugin configured properly

This commit is contained in:
R. Tyler Croy 2012-11-11 17:51:39 -08:00
parent 7f0964d728
commit 83ad946d05
6 changed files with 70 additions and 10 deletions

View File

@ -12,3 +12,11 @@ Feature: Start a chrome browser pointing at my Heroku site
"""
Sauce for Heroku has not yet been configured!
"""
Scenario: With Sauce configured
Given I have configured the plugin
When I run `heroku sauce:chrome`
Then the output should contain:
"""
Starting a Chrome session!
"""

View File

@ -2,3 +2,7 @@ Given /^I haven't already configured the plugin$/ do
# no op
end
Given /^I have configured the plugin$/ do
dump_config!
end

View File

@ -0,0 +1,16 @@
module SauceConfiguration
def config
{:username => 'tester', :access_key => 'testkey'}
end
def dump_config!
in_current_dir do
File.open('ondemand.yml', 'w+') do |f|
f.write(config.to_yaml)
end
end
end
end
World(SauceConfiguration)

View File

@ -1,5 +1,6 @@
require 'fileutils'
require 'aruba/cucumber'
require 'yaml'
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))

View File

@ -1,6 +1,7 @@
require 'heroku'
require 'heroku/command/base'
require 'sauce'
require 'yaml'
module Heroku
module Command
@ -56,16 +57,26 @@ access_key: #{apikey}
end
def chrome
unless configured?
c = configured?
unless c
display 'Sauce for Heroku has not yet been configured!'
return
else
display 'Starting a Chrome session!'
end
end
def configured?
File.exists?('ondemand.yml') ||
File.exists?(File.expand_path('~/.sauce/ondemand.yml'))
if File.exists?('ondemand.yml')
return YAML.load_file('ondemand.yml')
end
if File.exists?(File.expand_path('~/.sauce/ondemand.yml'))
return true
end
return false
end
end
end

View File

@ -7,21 +7,41 @@ describe Heroku::Command::Sauce do
let(:exists) { false }
before :each do
File.stub(:exists?).with(
'ondemand.yml').and_return(exists)
File.stub(:exists?).with(
File.expand_path('~/.sauce/ondemand.yml')).and_return(exists)
end
context 'by default' do
before :each do
File.stub(:exists?).with(
'ondemand.yml').and_return(false)
File.stub(:exists?).with(
File.expand_path('~/.sauce/ondemand.yml')).and_return(false)
end
it { subject.should_not be_configured }
end
context 'when configured' do
let(:exists) { true }
context 'configured with a local ondemand.yml' do
let(:config) do
{
'username' => 'niceguy',
'access_key' => 'sekret'
}
end
before :each do
File.should_receive(:exists?).with('ondemand.yml').and_return(true)
YAML.should_receive(:load_file).with('ondemand.yml').and_return(config)
end
it { subject.should be_configured }
it 'should return the configuration' do
result = subject.configured?
result.should be_instance_of(Hash)
expect(result['username']).to eql(config['username'])
expect(result['access_key']).to eql(config['access_key'])
end
end
end
end