cider_ci-rspec_support 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 273a75fe82aa49c3632476ceda4e74ff0e5e166f
4
+ data.tar.gz: f37d760fd65ddb5d571439f9912dd0e783048415
5
+ SHA512:
6
+ metadata.gz: 839fe13ffc70415a9f9f44d3acf94b140c8ff9f1a91d50ed0ce32b33920a99a6f07972334d21db8a453d4be474d298ee2fd68e04d3ecbe2827f1b2a6395b0597
7
+ data.tar.gz: 314797ff5c1a6bdc5a2b645b438267baffcf30bf29754ebcc9f48ee724830a5933c7b7e3d66ff97a4ab77f29e73f383ce16a8ff7a21a7496001ede9a1cdec8e3
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,89 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-01-06 15:11:15 +0100 using RuboCop version 0.28.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 7
9
+ Metrics/AbcSize:
10
+ Max: 50
11
+
12
+ # Offense count: 9
13
+ # Configuration parameters: CountComments.
14
+ Metrics/MethodLength:
15
+ Max: 29
16
+
17
+ # Offense count: 1
18
+ Style/AccessorMethodName:
19
+ Enabled: false
20
+
21
+ # Offense count: 2
22
+ Style/ClassAndModuleCamelCase:
23
+ Enabled: false
24
+
25
+ # Offense count: 2
26
+ Style/Documentation:
27
+ Enabled: false
28
+
29
+ # Offense count: 3
30
+ # Configuration parameters: Exclude.
31
+ Style/FileName:
32
+ Enabled: false
33
+
34
+ # Offense count: 1
35
+ # Configuration parameters: MinBodyLength.
36
+ Style/GuardClause:
37
+ Enabled: false
38
+
39
+ # Offense count: 1
40
+ # Configuration parameters: MaxLineLength.
41
+ Style/IfUnlessModifier:
42
+ Enabled: false
43
+
44
+ # Offense count: 5
45
+ Style/MultilineBlockChain:
46
+ Enabled: false
47
+
48
+ # Offense count: 2
49
+ # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
50
+ Style/Next:
51
+ Enabled: false
52
+
53
+ # Offense count: 1
54
+ Style/RescueModifier:
55
+ Enabled: false
56
+
57
+ # Offense count: 7
58
+ # Cop supports --auto-correct.
59
+ # Configuration parameters: AllowAsExpressionSeparator.
60
+ Style/Semicolon:
61
+ Enabled: false
62
+
63
+ # Offense count: 1
64
+ # Cop supports --auto-correct.
65
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
66
+ Style/SignalException:
67
+ Enabled: false
68
+
69
+ # Offense count: 1
70
+ # Cop supports --auto-correct.
71
+ Style/SpecialGlobalVars:
72
+ Enabled: false
73
+
74
+ # Offense count: 1
75
+ # Cop supports --auto-correct.
76
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
77
+ Style/StringLiterals:
78
+ Enabled: false
79
+
80
+ # Offense count: 1
81
+ # Cop supports --auto-correct.
82
+ Style/TrailingWhitespace:
83
+ Enabled: false
84
+
85
+ # Offense count: 1
86
+ Lint/Eval:
87
+ Enabled: false
88
+
89
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Thomas Schank
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Cider-CI Support for Rspec
2
+
3
+ This gem provides convenience executables to work with Rspec and Cider-CI.
4
+
5
+ See also [Cider-CI Support for Ruby and Ruby on Rails][].
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cider_ci-rspec_support', '~> 1.0.0'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+
18
+ ### Update
19
+
20
+ bundle exec cider-ci_rspec-support update spec/
21
+
22
+ This will read all specs and update or create the corresponding Cider-CI tasks
23
+ in `./cider-ci/tasks/rspec-tasks.yml` and
24
+ `./cider-ci/tasks/rspec-feature-tasks.yml` respectively. The target files can
25
+ be configured, try
26
+
27
+ bundle exec cider-ci_rspec-support --help
28
+
29
+
30
+ ### Check
31
+
32
+ bundle exec cider-ci_rspec-support check spec/
33
+
34
+ This will check if an update is required. It will print out a warning and exit
35
+ with non zero if so. It is recommended to use this command in a Cider-CI task
36
+ to tests if the specification is up to date.
37
+
38
+
39
+ [Cider-CI Support for Ruby and Ruby on Rails]: https://github.com/cider-ci/cider-ci_ruby-support
40
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env ruby
2
+ ###############################################################################
3
+ #
4
+ # Cider-CI Taks management for Rspec tests.
5
+ #
6
+ # Authors: Thomas Schank <DrTom@schank.ch>
7
+ #
8
+ ###############################################################################
9
+
10
+ ###############################################################################
11
+ # Read and write
12
+ ###############################################################################
13
+
14
+ require 'cider_ci/rspec_support'
15
+ require 'cider_ci/rspec_support/util'
16
+ require 'cider_ci/rspec_support/deep_merge'
17
+
18
+ require 'YAML'
19
+
20
+ def read_tasks(path)
21
+ Hash[CiderCI::RspecSupport::Util.deep_symbolize_keys(YAML.load_file(path))]
22
+ rescue
23
+ {}
24
+ end
25
+
26
+ def write_tasks(path, tasks)
27
+ abs_path = File.absolute_path(path)
28
+ FileUtils.mkdir_p File.dirname(abs_path)
29
+ File.open abs_path, 'w' do |f|
30
+ f.write Hash[
31
+ CiderCI::RspecSupport::Util.deep_stringify_keys(tasks).sort].to_yaml
32
+ end
33
+ end
34
+
35
+ def compute_output(tasks, file_path, template)
36
+ CiderCI::RspecSupport::DeepMerge.deep_merge(
37
+ Hash[tasks.map do |task|
38
+ [task.key, task.spec_properties(template)]
39
+ end],
40
+ read_tasks(file_path).select do|k|
41
+ tasks.map(&:key).map(&:to_sym).include? k
42
+ end)
43
+ end
44
+
45
+ ###############################################################################
46
+ # check, main, update
47
+ ###############################################################################
48
+
49
+
50
+ def update(options, collected)
51
+ write_tasks(options.rspec_tasks_path,
52
+ compute_output(collected.tasks,
53
+ options.rspec_tasks_path,
54
+ options.task_body_template))
55
+
56
+ write_tasks(options.rspec_feature_tasks_path,
57
+ compute_output(collected.feature_tasks,
58
+ options.rspec_feature_tasks_path,
59
+ options.feature_task_body_template))
60
+ end
61
+
62
+ def keys_equal?(tasks, file)
63
+ Set.new(tasks.map(&:key).map(&:to_s)) ==
64
+ Set.new(read_tasks(file).keys.map(&:to_s))
65
+ end
66
+
67
+ def check(options, collected)
68
+ unless keys_equal? collected.tasks, options.rspec_tasks_path
69
+ abort "Rspec tasks are out of date."
70
+ end
71
+
72
+ unless keys_equal? collected.feature_tasks, options.rspec_feature_tasks_path
73
+ abort "Rspec feature tasks are out of date."
74
+ end
75
+
76
+ puts "Rspec feature tasks and regular tasks are up to date."
77
+ exit 0
78
+ end
79
+
80
+ def main
81
+ options = default_options
82
+ parse_options options
83
+ command = ARGV.shift
84
+ collected = collect_rspec_tasks
85
+
86
+ case command
87
+ when 'update'
88
+ update options, collected
89
+ when 'check'
90
+ check options, collected
91
+ else
92
+ abort "Don't know command '#{command}'"
93
+ end
94
+ end
95
+
96
+ ###############################################################################
97
+ # Rspec
98
+ ###############################################################################
99
+
100
+ require 'cider_ci/rspec_support/collector'
101
+
102
+ def collect_rspec_tasks
103
+ rspec_args = ["--format", CiderCI::RspecSupport::Collector.to_s,
104
+ "--dry-run"].concat(ARGV)
105
+ RSpec::Core::Runner.run(rspec_args, $stderr, $stdout)
106
+
107
+ CiderCI::RspecSupport.collector
108
+ end
109
+
110
+ ###############################################################################
111
+ # Options
112
+ ###############################################################################
113
+
114
+ require 'optparse'
115
+ require 'ostruct'
116
+
117
+ def parse_options(options)
118
+ OptionParser.new do |opts|
119
+ opts.banner = 'Usage: cider-ci_rspec-support ' \
120
+ '[options] COMMAND [files or directories]'
121
+
122
+ opts.on('-f', '--rspec-feature-tasks FILE', String,
123
+ "default: #{options.rspec_feature_tasks_path}") do |f|
124
+ options.respec_feature_tasks = f
125
+ end
126
+
127
+ opts.on('-t', '--rspec-tasks FILE', String,
128
+ "default: #{options.rspec_tasks_path}") do |t|
129
+ options.rspec_tasks = t
130
+ end
131
+
132
+ opts.on(nil, '--task-body-template TEMPLATE', String,
133
+ "default: #{options.task_body_template}") do |t|
134
+ options.task_body_template = t
135
+ end
136
+
137
+ opts.on(nil, '--feature-task-body-template TEMPLATE', String,
138
+ "default: #{options.feature_task_body_template}") do |t|
139
+ options.feature_task_body_template = t
140
+ end
141
+ end.parse!
142
+ options
143
+ end
144
+
145
+ def default_options
146
+ options = OpenStruct.new
147
+ options.rspec_tasks_path = './.cider-ci/tasks/rspec-tasks.yml'
148
+ options.rspec_feature_tasks_path = './.cider-ci/tasks/rspec-feature-tasks.yml'
149
+
150
+ options.feature_task_body_template =
151
+ '%[DISPLAY=":$XVNC_PORT" bundle exec rspec "#{rspec_path}"]'
152
+
153
+ options.task_body_template = '%[bundle exec rspec "#{rspec_path}"]'
154
+
155
+ options
156
+ end
157
+
158
+ ###############################################################################
159
+ # here we go
160
+ ###############################################################################
161
+ main
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cider_ci/rspec_support'
5
+ require 'cider_ci/rspec_support/version'
6
+ require 'cider_ci/rspec_support/collector'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'cider_ci-rspec_support'
10
+ spec.version = ::CiderCI::RspecSupport::VERSION
11
+ spec.authors = ['Thomas Schank']
12
+ spec.email = ['DrTom@schank.ch']
13
+ spec.summary = 'Cider-CI support for Rspec'
14
+ spec.description = ''
15
+ spec.homepage = 'https://github.com/cider-ci/cider-ci_ruby-rspec-support'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(/^(test|spec|features)/)
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_runtime_dependency 'rspec', '~> 3.1'
27
+
28
+ spec.add_runtime_dependency 'rspec-core', '>= 3.0.0', '< 4.0.0'
29
+ end
@@ -0,0 +1,42 @@
1
+ require 'cider_ci/rspec_support'
2
+ require 'cider_ci/rspec_support/task'
3
+ require 'rspec/core'
4
+
5
+ module CiderCI
6
+ module RspecSupport
7
+ class Collector
8
+ RSpec::Core::Formatters.register self, :example_started
9
+
10
+ attr_reader :tasks
11
+ attr_reader :feature_tasks
12
+
13
+ def initialize(_output)
14
+ ::CiderCI::RspecSupport.collector = self
15
+ @tasks = Set.new
16
+ @feature_tasks = Set.new
17
+ end
18
+
19
+ def example_started(notification)
20
+ metadata = notification.example.metadata
21
+ case metadata[:type]
22
+ when :feature
23
+ @feature_tasks << Task.new(
24
+ file_path: metadata[:file_path],
25
+ line_number: metadata[:line_number],
26
+ description: metadata[:full_description])
27
+ else
28
+ if present? metadata[:file_path]
29
+ @tasks << Task.new(
30
+ file_path: metadata[:file_path],
31
+ line_number: nil,
32
+ description: metadata[:example_group][:description])
33
+ end
34
+ end
35
+ end
36
+
37
+ def present?(str)
38
+ str && !str.gsub(/\s+/, '').empty?
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,35 @@
1
+ require 'set'
2
+
3
+ module CiderCI
4
+ module RspecSupport
5
+ module DeepMerge
6
+ class << self
7
+ def deep_merge(obj1, obj2)
8
+ if obj1.is_a?(Hash) && obj2.is_a?(Hash)
9
+ deep_merge_hashes obj1, obj2
10
+ else
11
+ obj2
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def keys(h1, h2)
18
+ Set.new(h1.keys) + Set.new(h2.keys)
19
+ end
20
+
21
+ def deep_merge_hashes(h1, h2)
22
+ Hash[(keys(h1, h2)).map do |k|
23
+ [k, if h1.key?(k) && h2.key?(k)
24
+ deep_merge(h1[k], h2[k])
25
+ elsif h2.key?(k)
26
+ h2[k]
27
+ else
28
+ h1[k]
29
+ end]
30
+ end]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ require 'digest'
2
+
3
+ module CiderCI
4
+ module RspecSupport
5
+ class Task
6
+
7
+
8
+ attr_reader :properties
9
+
10
+ def initialize(properties)
11
+ @properties = properties.freeze
12
+ end
13
+
14
+ def hash
15
+ Digest.hexencode(Digest::MD5.digest(rspec_path)).to_i(36)
16
+ end
17
+
18
+ def eql?(other)
19
+ rspec_path == other.rspec_path
20
+ end
21
+
22
+ def rspec_path
23
+ [@properties[:file_path], @properties[:line_number]].compact.join(":")
24
+ end
25
+
26
+ alias_method :key, :rspec_path
27
+
28
+ def spec_properties(script_main_body_template)
29
+ { name: @properties[:description],
30
+ scripts: {
31
+ main: {
32
+ body: eval(script_main_body_template)
33
+ }
34
+ }
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require 'set'
2
+ module CiderCI
3
+ module RspecSupport
4
+ module Util
5
+ IDENDITY = ->(x) { x }
6
+ class << self
7
+ def transform(object,
8
+ key_transformer = IDENDITY,
9
+ value_transformer = IDENDITY)
10
+ case object
11
+ when Hash
12
+ Hash[object.map do |k, v|
13
+ [key_transformer.call(k),
14
+ transform(v, key_transformer, value_transformer)]
15
+ end]
16
+ when Array
17
+ object.map { |v| transform(v, key_transformer, value_transformer) }
18
+ else
19
+ value_transformer.call(object)
20
+ end
21
+ end
22
+
23
+ def deep_symbolize_keys(object)
24
+ transform(object, ->(x) { x.to_sym })
25
+ end
26
+
27
+ def deep_stringify_keys(object)
28
+ transform(object, ->(x) { x.to_s })
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module CiderCI
2
+ module RspecSupport
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'cider_ci/rspec_support/version'
2
+
3
+ module CiderCI
4
+ module RspecSupport
5
+ class << self
6
+ attr_accessor :collector
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cider_ci-rspec_support
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Schank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-core
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: 4.0.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.0
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 4.0.0
89
+ description: ''
90
+ email:
91
+ - DrTom@schank.ch
92
+ executables:
93
+ - cider-ci_rspec-support
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".rubocop.yml"
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/cider-ci_rspec-support
104
+ - cider_ci-rspec_support.gemspec
105
+ - lib/cider_ci/rspec_support.rb
106
+ - lib/cider_ci/rspec_support/collector.rb
107
+ - lib/cider_ci/rspec_support/deep_merge.rb
108
+ - lib/cider_ci/rspec_support/task.rb
109
+ - lib/cider_ci/rspec_support/util.rb
110
+ - lib/cider_ci/rspec_support/version.rb
111
+ homepage: https://github.com/cider-ci/cider-ci_ruby-rspec-support
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.2.2
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Cider-CI support for Rspec
135
+ test_files: []
136
+ has_rdoc: