kender 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDQwMWQ5ZGYwMmJjOTQ4OGUwYTA0MDE2YWNjYjY4YjJmOWUyYzUzOA==
4
+ YjViZmI3ZGQwMjE4YjgyYjliOGNkOWE4ZmIwMzlmZjE1YTdlYjRmZA==
5
5
  data.tar.gz: !binary |-
6
- MzQzODJkYzUwY2NlOWNkMjlmZjAyZjljNGRmYTNmMjlkZTA3ZmM1OQ==
6
+ ZjVlMjIxYWI4NzZjYWYxZThkYmZkOTIyZjgyYWNlMTM1MWQzMmIyZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODgwNWZkY2M3OTIzODZiMjc2ZmRjNGVmZTNjNTRkZTgxZWQ3NDZhYWY1MmY3
10
- ZGQxZTQ2ZTQwZTNlNGMxZjc4MGE0MTgyMGE5Y2YyYWM3MGI5Njc2ZWYyZjZi
11
- YzkyMzlmZGUzMjNmODY2YmRhMjhiMmVlYzkzNTg2M2Y1OGNmNDU=
9
+ N2MwMWU2OGQ4M2Q0OWJjZGY2ZDU0ZmNhMmE0NGU3ZGNhNTcwMjU1NjllMTIx
10
+ ZDIzYmZhM2M3ZDI0N2Y4MTljYzYwM2Q4NDZlMWE0ZDAwNGM5ZWEyNjA4MjJk
11
+ YzkyM2EwN2MzY2Q1MDIxYWJlNTY2YWYyNjE3NGRmZWZlYmJjYjA=
12
12
  data.tar.gz: !binary |-
13
- YWMzYzI2NWY3MGRmZTI1MGMzMmRkNDBiNmRjNThlOTFmMDk5MWMzN2EzODcy
14
- ODE5OGQ2OTFhMzVjMWMwNzJmNzIzZTFlOWI3YmQ3YmQ0ODczMzNjMmQ0YWYx
15
- ZjE3NTJjNjgwYjU2N2Q2ZDNmZjc4MDM3ODhjMjcyMTk4YzRhNmU=
13
+ MjlhZGQwZjA5M2ZiYjExZGU5ZGI1ZTIzZWQxNzU5NGQ2Y2FjNGJhZGJlNjQ3
14
+ YmJhYmUzZjRmMTRmN2I0YTM2NjlhMWQ4ZjFiNTY1Y2IxNmViNTI1NWFmM2Iz
15
+ NTU1M2M5MDY1OTQ0MDg0MDhkOTRlNThlZmVjOWY0MmYyNzFiZGU=
@@ -0,0 +1,13 @@
1
+ Feature: Install
2
+
3
+ In Rails projects, Kender tasks are loaded automatically. For other
4
+ projects, add `require 'kender/tasks'` to your `Rakefile` or wherever your
5
+ local rake tasks are defined.
6
+
7
+ Scenario: Require Kender tasks in Rakefile
8
+ Given a file named "Rakefile" with:
9
+ """
10
+ require 'kender/tasks'
11
+ """
12
+ When I run `rake ci`
13
+ Then the exit status should be 0
@@ -0,0 +1,49 @@
1
+ Feature: Scenarios
2
+ Kender is able to run scenarios using the cucumber tool.
3
+
4
+ Background:
5
+ Given a file named "Gemfile" with:
6
+ """
7
+ source 'https://rubygems.org'
8
+ gem 'cucumber', '~>1.3'
9
+ """
10
+ And I run `bundle install`
11
+
12
+ Scenario: The project has no scenarios to run but cucumber is executed
13
+ When I run `rake ci`
14
+ Then it should pass with:
15
+ """
16
+ 0 scenarios
17
+ 0 steps
18
+ """
19
+
20
+ Scenario: The project has some passing scenarios to run
21
+ Given a file named "features/testing.feature" with:
22
+ """
23
+ Feature: test
24
+ This is a test of my product
25
+ Scenario: first test
26
+ """
27
+ When I run `rake ci`
28
+ Then it should pass with:
29
+ """
30
+ 1 scenario (1 passed)
31
+ 0 steps
32
+ """
33
+
34
+ Scenario: The project has some non passing scenarios to run
35
+ Given a file named "features/testing.feature" with:
36
+ """
37
+ Feature: test
38
+ This is a test of my product
39
+ Scenario: first test
40
+ Then failing step
41
+ """
42
+ And a file named "features/step_definitions/steps.rb" with:
43
+ """
44
+ Given(/^failing step$/) do
45
+ raise 'failed'
46
+ end
47
+ """
48
+ When I run `rake ci`
49
+ Then the exit status should not be 0
@@ -0,0 +1,6 @@
1
+ require 'aruba/cucumber'
2
+ require 'kender'
3
+
4
+ Before do
5
+ @aruba_timeout_seconds = 10
6
+ end
@@ -0,0 +1,5 @@
1
+ Before do
2
+ write_file("Rakefile", "require 'kender/tasks'")
3
+ create_dir('features')
4
+ create_dir('spec')
5
+ end
@@ -11,11 +11,11 @@ module Kender
11
11
  end
12
12
 
13
13
  def available?
14
- raise RuntimeError, "Command failed: #{name}, availability status undefined."
14
+ abort "Command failed: #{name}, availability status undefined."
15
15
  end
16
16
 
17
17
  def execute
18
- raise RuntimeError, "Command failed: #{command}" unless run.success?
18
+ abort "Command failed: #{command}" unless run.success?
19
19
  end
20
20
 
21
21
  #TODO: system reload all the gems again, avoid this.
@@ -43,9 +43,17 @@ module Kender
43
43
  end
44
44
 
45
45
  end
46
+
47
+ private
48
+
49
+ def in_gemfile?(gem_name)
50
+ Bundler.definition.specs.any?{ |spec| spec.name == gem_name }
51
+ end
52
+
46
53
  end
47
54
  end
48
55
 
56
+ require_relative 'commands/consistency_fail'
49
57
  require_relative 'commands/jasmine'
50
58
  require_relative 'commands/brakeman'
51
59
  require_relative 'commands/bundle_audit'
@@ -2,7 +2,7 @@ module Kender
2
2
  class Brakeman < Command
3
3
 
4
4
  def available?
5
- defined?(::Brakeman)
5
+ in_gemfile?('brakeman')
6
6
  end
7
7
 
8
8
  def command
@@ -2,7 +2,7 @@ module Kender
2
2
  class BundleAudit < Command
3
3
 
4
4
  def available?
5
- defined?(::Bundler::Audit)
5
+ in_gemfile?('bundler-audit')
6
6
  end
7
7
 
8
8
  def command
@@ -0,0 +1,13 @@
1
+ module Kender
2
+ class ConsistencyFail < Command
3
+
4
+ def available?
5
+ in_gemfile?("consistency_fail")
6
+ end
7
+
8
+ def command
9
+ 'bundle exec consistency_fail'
10
+ end
11
+
12
+ end
13
+ end
@@ -2,7 +2,7 @@ module Kender
2
2
  class Cucumber < Command
3
3
 
4
4
  def available?
5
- defined?(Cucumber) and not(ENV['VALIDATE_PROJECT'])
5
+ in_gemfile?("cucumber") and not(ENV['VALIDATE_PROJECT'])
6
6
  end
7
7
 
8
8
  def command
@@ -2,7 +2,7 @@ module Kender
2
2
  class Rspec < Command
3
3
 
4
4
  def available?
5
- defined?(RSpec) and not(ENV['VALIDATE_PROJECT'])
5
+ in_gemfile?("rspec") and not(ENV['VALIDATE_PROJECT'])
6
6
  end
7
7
 
8
8
  def command
@@ -2,7 +2,7 @@ module Kender
2
2
  class Shamus < Command
3
3
 
4
4
  def available?
5
- defined?(Shamus) and ENV['VALIDATE_PROJECT']
5
+ in_gemfile?("shamus") and ENV['VALIDATE_PROJECT']
6
6
  end
7
7
 
8
8
  def command
@@ -2,7 +2,7 @@ module Kender
2
2
  class TestUnit < Command
3
3
 
4
4
  def available?
5
- defined?(Test::Unit) and not(ENV['VALIDATE_PROJECT'])
5
+ in_gemfile?('test-unit') and not(ENV['VALIDATE_PROJECT'])
6
6
  end
7
7
 
8
8
  def command
data/lib/kender/github.rb CHANGED
@@ -21,6 +21,11 @@ module Kender
21
21
  # TODO: Refactor the following code to use gems like git/grit/rugged and
22
22
  # octokit. ~asmith
23
23
 
24
+ unless config.github_auth_token
25
+ puts "Skipping setting the status on Github to #{state} because the access token is not configured"
26
+ return
27
+ end
28
+
24
29
  body = %Q({
25
30
  "state": "#{state.to_s}",
26
31
  "target_url": "#{config.build_url}",
@@ -28,28 +33,39 @@ module Kender
28
33
  })
29
34
  commit = `git log -1 --format=format:%H`
30
35
  remotes = `git remote --verbose`
36
+ remote_name = ENV['GITHUB_REMOTE'] || 'origin'
31
37
 
32
- unless repo = /^origin\s+git@github.com:(\w+\/\w+)\b/.match(remotes)[1]
33
- put "Could not establish GitHub repo name from 'origin' remote"
38
+ unless repo = /^#{remote_name}\s+git@(\w+\.)?github.com:([\w-]+\/[\w-]+)\b/.match(remotes).to_a.last
39
+ puts "Could not establish GitHub repo name from '#{remote_name}' remote"
34
40
  return
35
41
  end
36
-
37
42
  uri = URI("https://api.github.com/repos/#{repo}/statuses/#{commit}?access_token=#{config.github_auth_token}")
38
43
 
39
- if config.github_auth_token
40
- puts "Setting #{repo} commit #{commit} status to '#{state}' on GitHub"
41
- else
42
- puts "Skipping setting #{repo} commit #{commit} status to '#{state}' on GitHub because access token not configured"
43
- return
44
- end
44
+ puts "Setting #{repo} commit #{commit} status to '#{state}' on GitHub"
45
45
 
46
- Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
47
- response = http.post(uri.request_uri, body)
48
- unless response.is_a?(Net::HTTPCreated)
49
- puts "Setting commit status FAILED", response
46
+ ensure_real_connection do
47
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
48
+ response = http.post(uri.request_uri, body)
49
+ unless response.is_a?(Net::HTTPCreated)
50
+ puts "Setting commit status FAILED", response
51
+ end
50
52
  end
51
53
  end
52
54
  end
55
+
56
+ def ensure_real_connection
57
+ if !defined?(WebMock)
58
+ return yield
59
+ end
60
+ if !WebMock.net_connect_allowed?
61
+ WebMock.allow_net_connect!
62
+ yield
63
+ WebMock.disable_net_connect!
64
+ else
65
+ yield
66
+ end
67
+ end
68
+
53
69
  end
54
70
  end
55
71
 
@@ -5,6 +5,15 @@ require 'kender/configuration'
5
5
  require 'kender/github'
6
6
  require 'kender/command'
7
7
 
8
+ # Helper method to call rake tasks without blowing up when they do not exists
9
+ # @Return: false when it could not be executed or there was some error.
10
+ def run_successfully?(tasks)
11
+ [*tasks].all? do |task|
12
+ Rake::Task.task_defined?(task) && Rake::Task[task].invoke
13
+ end
14
+ end
15
+
16
+ # This is the task we want the user to use all the time.
8
17
  desc "Configure and run continuous integration tests then clean up"
9
18
  task :ci => ['ci:status:pending'] do
10
19
  begin
@@ -13,7 +22,6 @@ task :ci => ['ci:status:pending'] do
13
22
  Rake::Task["ci:status:success"].invoke
14
23
  rescue Exception => e
15
24
  Rake::Task["ci:status:failure"].invoke
16
-
17
25
  # Ensure that this task still fails.
18
26
  raise e
19
27
  ensure
@@ -23,11 +31,9 @@ end
23
31
 
24
32
  namespace :ci do
25
33
 
34
+ # UI for the user, these are tasks the user can use
26
35
  desc "Configure the app to run continuous integration tests"
27
- # Could depend on 'db:schema:load' or 'db:setup' here instead of 'db:migrate'
28
- # if the 'db/schema.rb' file was committed to the repo (as per Rails
29
- # recommendations).
30
- task :config => ['ci:env', 'config:all', 'ci:setup_db']
36
+ task :config => ['ci:env', 'ci:config_project', 'ci:setup_db']
31
37
 
32
38
  desc "Run continuous integration tests with the current configuration"
33
39
  task :run => ['ci:env'] + Kender::Command.all_tasks
@@ -35,6 +41,15 @@ namespace :ci do
35
41
  desc "Destroy resources created externally for the continuous integration run, e.g. drops databases"
36
42
  task :clean => ['ci:env', 'ci:drop_db']
37
43
 
44
+ # Automatically create rake task for each individual command.
45
+ Kender::Command.all.each do |command|
46
+ desc "Individual task for #{command.name}, in parallel if available."
47
+ task command.name do
48
+ command.execute
49
+ end
50
+ end
51
+
52
+ # The following tasks are internal to us, without description, the user can not discover them
38
53
  task :env do
39
54
  if defined?(Rails)
40
55
  # Default to the 'test' environment unless otherwise specified. This
@@ -47,33 +62,40 @@ namespace :ci do
47
62
  end
48
63
  end
49
64
 
50
- # Automatically create rake task for each individual command.
51
- Kender::Command.all.each do |command|
52
- desc "Individual task for #{command.name}, in parallel if available."
53
- task command.name do
54
- command.execute
65
+ task :config_project do
66
+ unless run_successfully?('config:all')
67
+ puts 'Your project could not be configured, a config:all task needed. Consider installing dice_bag'
55
68
  end
56
69
  end
57
70
 
58
- desc "Generic task to setup your databases, in parallel if available."
59
71
  task :setup_db do
60
- if !defined?(ParallelTests)
61
- Rake::Task['db:create'].invoke
62
- Rake::Task['db:migrate'].invoke
72
+ if Rake::Task.task_defined?('db:create')
73
+ if !defined?(ParallelTests)
74
+ unless run_successfully?(['db:create', 'db:migrate'])
75
+ puts 'The DB could not be set up successfully.'
76
+ end
77
+ else
78
+ #TODO: invoke on the task did not work. Why?
79
+ system('bundle exec rake parallel:create')
80
+ system('bundle exec rake parallel:prepare')
81
+ end
63
82
  else
64
- #TODO: invoke on the task did not work. Why?
65
- system('bundle exec rake parallel:create')
66
- system('bundle exec rake parallel:prepare')
83
+ puts "no databases tasks found."
67
84
  end
68
85
  end
69
86
 
70
- desc "Generic task to drop your databases, in parallel if available."
71
87
  task :drop_db do
72
- if !defined?(ParallelTests)
73
- Rake::Task['db:drop'].invoke
88
+ if Rake::Task.task_defined?('db:drop')
89
+ if !defined?(ParallelTests)
90
+ unless run_successfully?('db:drop')
91
+ puts 'The DB could not be dropped.'
92
+ end
93
+ else
94
+ #TODO: invoke on the task did not work. Why?
95
+ system('bundle exec rake parallel:drop')
96
+ end
74
97
  else
75
- #TODO: invoke on the task did not work. Why?
76
- system('bundle exec rake parallel:drop')
98
+ puts "no databases tasks found."
77
99
  end
78
100
  end
79
101
 
@@ -1,3 +1,3 @@
1
1
  module Kender
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Smith
@@ -25,6 +25,34 @@ dependencies:
25
25
  - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: aruba
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.5.2
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 0.5.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
28
56
  description:
29
57
  email:
30
58
  - asmith@mdsol.com
@@ -33,10 +61,15 @@ executables: []
33
61
  extensions: []
34
62
  extra_rdoc_files: []
35
63
  files:
64
+ - features/install.feature
65
+ - features/scenarios.feature
66
+ - features/support/env.rb
67
+ - features/support/hooks.rb
36
68
  - lib/kender.rb
37
69
  - lib/kender/command.rb
38
70
  - lib/kender/commands/brakeman.rb
39
71
  - lib/kender/commands/bundle_audit.rb
72
+ - lib/kender/commands/consistency_fail.rb
40
73
  - lib/kender/commands/cucumber.rb
41
74
  - lib/kender/commands/jasmine.rb
42
75
  - lib/kender/commands/rspec.rb
@@ -72,5 +105,9 @@ signing_key:
72
105
  specification_version: 4
73
106
  summary: Kender is a library of rake tasks that provides a consistent framework for
74
107
  continuous integration (CI).
75
- test_files: []
108
+ test_files:
109
+ - features/install.feature
110
+ - features/scenarios.feature
111
+ - features/support/env.rb
112
+ - features/support/hooks.rb
76
113
  has_rdoc: