2014-01-15 14:38:48 +00:00
|
|
|
require 'webmock'
|
|
|
|
|
2014-09-22 14:30:25 +00:00
|
|
|
class Spinach::Features::ProjectHooks < Spinach::FeatureSteps
|
2012-09-27 20:52:08 +00:00
|
|
|
include SharedAuthentication
|
|
|
|
include SharedProject
|
|
|
|
include SharedPaths
|
|
|
|
include RSpec::Matchers
|
|
|
|
include RSpec::Mocks::ExampleMethods
|
2014-01-15 14:38:48 +00:00
|
|
|
include WebMock::API
|
2012-09-27 20:52:08 +00:00
|
|
|
|
2014-07-27 20:26:23 +00:00
|
|
|
step 'project has hook' do
|
2012-11-06 03:31:55 +00:00
|
|
|
@hook = create(:project_hook, project: current_project)
|
2012-09-27 20:52:08 +00:00
|
|
|
end
|
|
|
|
|
2014-07-27 20:26:23 +00:00
|
|
|
step 'I own empty project with hook' do
|
|
|
|
@project = create(:empty_project,
|
|
|
|
name: 'Empty Project', namespace: @user.namespace)
|
|
|
|
@hook = create(:project_hook, project: current_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
step 'I should see project hook' do
|
2012-09-27 20:52:08 +00:00
|
|
|
page.should have_content @hook.url
|
|
|
|
end
|
|
|
|
|
2014-07-27 20:26:23 +00:00
|
|
|
step 'I submit new hook' do
|
2012-09-27 20:52:08 +00:00
|
|
|
@url = Faker::Internet.uri("http")
|
|
|
|
fill_in "hook_url", with: @url
|
|
|
|
expect { click_button "Add Web Hook" }.to change(ProjectHook, :count).by(1)
|
|
|
|
end
|
|
|
|
|
2014-07-27 20:26:23 +00:00
|
|
|
step 'I should see newly created hook' do
|
2014-09-24 06:28:41 +00:00
|
|
|
current_path.should == project_hooks_path(current_project)
|
2012-09-27 20:52:08 +00:00
|
|
|
page.should have_content(@url)
|
|
|
|
end
|
|
|
|
|
2014-07-27 20:26:23 +00:00
|
|
|
step 'I click test hook button' do
|
2014-01-15 14:38:48 +00:00
|
|
|
stub_request(:post, @hook.url).to_return(status: 200)
|
2012-09-27 20:52:08 +00:00
|
|
|
click_link 'Test Hook'
|
|
|
|
end
|
|
|
|
|
2014-07-29 09:49:46 +00:00
|
|
|
step 'I click test hook button with invalid URL' do
|
|
|
|
stub_request(:post, @hook.url).to_raise(SocketError)
|
|
|
|
click_link 'Test Hook'
|
|
|
|
end
|
|
|
|
|
2014-07-27 20:26:23 +00:00
|
|
|
step 'hook should be triggered' do
|
2014-09-24 06:28:41 +00:00
|
|
|
current_path.should == project_hooks_path(current_project)
|
2014-07-27 20:26:23 +00:00
|
|
|
page.should have_selector '.flash-notice',
|
|
|
|
text: 'Hook successfully executed.'
|
|
|
|
end
|
|
|
|
|
|
|
|
step 'I should see hook error message' do
|
|
|
|
page.should have_selector '.flash-alert',
|
|
|
|
text: 'Hook execution failed. '\
|
|
|
|
'Ensure the project has commits.'
|
2012-09-27 20:52:08 +00:00
|
|
|
end
|
2014-07-29 09:49:46 +00:00
|
|
|
|
|
|
|
step 'I should see hook service down error message' do
|
|
|
|
page.should have_selector '.flash-alert',
|
|
|
|
text: 'Hook execution failed. '\
|
|
|
|
'Ensure hook URL is correct and '\
|
|
|
|
'service is up.'
|
|
|
|
end
|
2012-09-27 20:52:08 +00:00
|
|
|
end
|