cspec 0.1.2 → 0.1.5
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 +4 -4
- data/.github/workflows/ruby.yml +48 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +28 -0
- data/Gemfile.lock +1 -1
- data/README.md +26 -35
- data/cspec.gemspec +1 -0
- data/examples/basic/Gemfile +4 -0
- data/examples/basic/Gemfile.lock +13 -0
- data/examples/basic/myspec.rb +13 -0
- data/examples/basic/specs.csv +2 -0
- data/examples/class_methods/Gemfile +4 -0
- data/examples/class_methods/Gemfile.lock +13 -0
- data/examples/class_methods/myspec.rb +17 -0
- data/examples/class_methods/specs.csv +3 -0
- data/examples/method_args/Gemfile +4 -0
- data/examples/method_args/Gemfile.lock +13 -0
- data/examples/method_args/myspec.rb +13 -0
- data/examples/method_args/specs.csv +2 -0
- data/lib/cspec/loader.rb +30 -0
- data/lib/{result.rb → cspec/result.rb} +10 -2
- data/lib/cspec/runner.rb +31 -0
- data/lib/cspec/version.rb +1 -1
- data/lib/cspec.rb +22 -72
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 714f4f91b2400d6116f74df4ffbe5ca1bc9c5bec537e732e40be0b98a7725257
|
4
|
+
data.tar.gz: fba0bb895cee486513aa75eca6b822bf4dc111e9f3036638addbfb86a56d2088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0f7fe559c1e5cc941cda78d4d2eeb2b78a29b69364c5b0c92581772d7447cad98a5f54ce035dd243020d08487dd5d33c3254d8ad58200493d5aaad17ad11a2
|
7
|
+
data.tar.gz: a5da9ae8fd9f37aa85a77f5f8ea9ba56a9b89d38bfdc50724398b49722ee166ffb106515f65137d9a841d572793317265def0e2a173292ef3ccdbf45d7c39418
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Install Rubocop
|
35
|
+
run: gem install rubocop
|
36
|
+
- name: Run Rubocop
|
37
|
+
run: rubocop
|
38
|
+
- name: Run Specs
|
39
|
+
run: bundle exec rspec
|
40
|
+
- name: Run Basic Example
|
41
|
+
working-directory: ./examples/basic
|
42
|
+
run: bundle install && bundle exec ruby myspec.rb
|
43
|
+
- name: Run Method Args Example
|
44
|
+
working-directory: ./examples/method_args
|
45
|
+
run: bundle install && bundle exec ruby myspec.rb
|
46
|
+
- name: Run Class Methods Example
|
47
|
+
working-directory: ./examples/class_methods
|
48
|
+
run: bundle install && bundle exec ruby myspec.rb
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-03-04 05:00:00 UTC using RuboCop version 1.25.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 3
|
10
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
11
|
+
# IgnoredMethods: refine
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Max: 50
|
14
|
+
|
15
|
+
# Offense count: 1
|
16
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Max: 11
|
19
|
+
|
20
|
+
# Offense count: 1
|
21
|
+
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
22
|
+
Metrics/ParameterLists:
|
23
|
+
Max: 6
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
Security/Eval:
|
27
|
+
Exclude:
|
28
|
+
- 'lib/cspec.rb'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,43 +1,34 @@
|
|
1
1
|
# Cspec
|
2
2
|
|
3
|
-
|
3
|
+
## Running test cases via CSV
|
4
4
|
|
5
|
-
|
5
|
+
The goal of this project is to have a centralised location where all specs can be run
|
6
6
|
|
7
|
-
##
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
7
|
+
## Quick start
|
10
8
|
|
9
|
+
* Add this to your `Gemfile`
|
11
10
|
```ruby
|
12
|
-
gem 'cspec'
|
11
|
+
gem 'cspec'
|
12
|
+
```
|
13
|
+
* Create a CSV named `specs.csv` with the following spec
|
14
|
+
```csv
|
15
|
+
class,name,type,initialize_params_1,method,method_args_1,expected
|
16
|
+
MyClass,my test,,hello,,world
|
17
|
+
```
|
18
|
+
* Create a file named `my_csv_specs.rb` to run the specs
|
19
|
+
```ruby
|
20
|
+
require 'cspec'
|
21
|
+
|
22
|
+
# The implementation of the Ruby class being testedc
|
23
|
+
class MyClass
|
24
|
+
def hello
|
25
|
+
'world'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Running the specs
|
30
|
+
result = CSpec::Runner.run!("#{Dir.pwd}/specs.csv")
|
31
|
+
puts "Success: #{result}"
|
13
32
|
```
|
14
33
|
|
15
|
-
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install cspec
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
-
|
41
|
-
## Code of Conduct
|
42
|
-
|
43
|
-
Everyone interacting in the Cspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cspec/blob/master/CODE_OF_CONDUCT.md).
|
34
|
+
* Run with `ruby my_csv_specs.rb`
|
data/cspec.gemspec
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cspec'
|
4
|
+
|
5
|
+
class MyClass
|
6
|
+
def self.hello
|
7
|
+
'world'
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.say(name)
|
11
|
+
"Hello, #{name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
result = CSpec::Runner.run!("#{Dir.pwd}/specs.csv")
|
16
|
+
puts "Success: #{result}"
|
17
|
+
exit result ? 0 : 1
|
data/lib/cspec/loader.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CSpec
|
4
|
+
module Loader
|
5
|
+
def self.load(filename)
|
6
|
+
::CSV.open(filename, headers: :first_row).map(&:to_h)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.process_args(spec)
|
10
|
+
process_arg(spec, /method_arg_\d+/, 'method_args').merge(
|
11
|
+
process_arg(spec, /initialization_arg_\d+/, 'initialization_args')
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.process_arg(spec, regex, aggregate_key)
|
16
|
+
spec.merge({
|
17
|
+
aggregate_key => spec.keys
|
18
|
+
.select { |k| k.match?(regex) }
|
19
|
+
.inject([]) { |values, key| values << spec[key] }
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.validate(filename)
|
24
|
+
headers = CSV.open(filename, &:readline)
|
25
|
+
%w[class type name method expected].map do |required_header|
|
26
|
+
"Need header: #{required_header}" unless headers.include?(required_header)
|
27
|
+
end.reject(&:nil?)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,9 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CSpec
|
2
4
|
class Result
|
3
5
|
attr_reader :name, :class, :method, :error, :description, :details
|
4
6
|
|
5
7
|
def self.success?(results)
|
6
|
-
results.count {|r|r.error
|
8
|
+
results.count { |r| !r.error.nil? }.zero?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.from_spec(spec, error = nil)
|
12
|
+
Result.new(spec['name'], spec['class'], spec['method'],
|
13
|
+
error, spec['description'], nil)
|
7
14
|
end
|
8
15
|
|
9
16
|
def initialize(name, klass, method, error, description, details)
|
@@ -25,7 +32,8 @@ module CSpec
|
|
25
32
|
end
|
26
33
|
|
27
34
|
def to_s
|
28
|
-
|
35
|
+
"name: #{name}, class: #{self.class}, method: #{method}," \
|
36
|
+
" error: #{error}, description: #{description}, details: #{details}"
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
data/lib/cspec/runner.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CSpec
|
4
|
+
module Runner
|
5
|
+
def self.run!(filepath)
|
6
|
+
errors = Loader.validate(filepath)
|
7
|
+
unless errors.empty?
|
8
|
+
puts errors
|
9
|
+
return false
|
10
|
+
end
|
11
|
+
specs = Loader.load(filepath)
|
12
|
+
results = run(specs)
|
13
|
+
|
14
|
+
return true if CSpec::Result.success?(results)
|
15
|
+
|
16
|
+
ResultsOutputter.display(results)
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.run(specs)
|
21
|
+
specs.map do |spec|
|
22
|
+
result = ::CSpec::DataType.convert(::CSpec::Executer.do(spec))
|
23
|
+
expected = ::CSpec::DataType.convert(spec[:expected])
|
24
|
+
error_msg = "Expected #{spec[:expected]}, got: #{result}" if result != expected
|
25
|
+
Result.from_spec(spec, error_msg)
|
26
|
+
rescue StandardError => e
|
27
|
+
Result.from_spec(spec, e.inspect)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/cspec/version.rb
CHANGED
data/lib/cspec.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'cspec/version'
|
4
|
+
require 'cspec/runner'
|
5
|
+
require 'cspec/loader'
|
6
|
+
require 'cspec/result'
|
7
|
+
|
4
8
|
require 'csv'
|
5
|
-
require_relative 'result'
|
6
9
|
|
7
10
|
module CSpec
|
8
11
|
module ResultsOutputter
|
@@ -13,89 +16,36 @@ module CSpec
|
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
module Loader
|
17
|
-
def self.load(filename)
|
18
|
-
::CSV.open(filename, headers: :first_row).map(&:to_h)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.validate(filename)
|
22
|
-
errors = []
|
23
|
-
headers = CSV.open(filename, &:readline)
|
24
|
-
%w[class type name method expected].each do |required_header|
|
25
|
-
errors << "Need header: #{required_header}" unless headers.include?(required_header)
|
26
|
-
end
|
27
|
-
errors
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
19
|
module Executer
|
32
20
|
def self.do_instance(spec)
|
33
|
-
class_under_test = Object.const_get(spec[
|
34
|
-
instance_under_test = class_under_test.new(*spec[
|
35
|
-
instance_under_test.send(spec[
|
21
|
+
class_under_test = Object.const_get(spec['class'])
|
22
|
+
instance_under_test = class_under_test.new(*spec['initialization_args'])
|
23
|
+
instance_under_test.send(spec['method'], *spec['method_args'])
|
36
24
|
end
|
37
25
|
|
38
26
|
def self.do_class(spec)
|
39
|
-
class_under_test = Object.const_get(spec[
|
40
|
-
class_under_test.send(spec[
|
27
|
+
class_under_test = Object.const_get(spec['class'])
|
28
|
+
class_under_test.send(spec['method'], *spec['method_args'])
|
41
29
|
end
|
42
|
-
end
|
43
30
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
elsif input =~ /^\[.*\]$/
|
51
|
-
eval(input)
|
52
|
-
elsif ['', nil, 'nil'].include?(input)
|
53
|
-
nil
|
54
|
-
else
|
55
|
-
input.to_s
|
31
|
+
def self.do(spec)
|
32
|
+
case spec[:type]
|
33
|
+
when 'class'
|
34
|
+
do_class(spec)
|
35
|
+
when 'instance'
|
36
|
+
do_instance(spec)
|
56
37
|
end
|
57
38
|
end
|
58
39
|
end
|
59
40
|
|
60
|
-
module
|
61
|
-
def self.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
specs = Loader.load(filepath)
|
68
|
-
results = run(specs)
|
69
|
-
|
70
|
-
if CSpec::Result.success?(results)
|
71
|
-
return true
|
72
|
-
else
|
73
|
-
ResultsOutputter.display(results)
|
74
|
-
return false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.run(specs)
|
79
|
-
results = []
|
80
|
-
specs.each do |spec|
|
81
|
-
result = case spec[:type]
|
82
|
-
when 'class'
|
83
|
-
::CSpec::Executer.do_class(spec)
|
84
|
-
when 'instance'
|
85
|
-
::CSpec::Executer.do_instance(spec)
|
86
|
-
end
|
41
|
+
module DataType
|
42
|
+
def self.convert(input)
|
43
|
+
return input.to_f if input =~ /^\d+\.\d+$/
|
44
|
+
return input.to_i if input =~ /^\d+$/
|
45
|
+
return eval(input) if input =~ /^\[.*\]$/
|
46
|
+
return nil if ['', nil, 'nil'].include?(input)
|
87
47
|
|
88
|
-
|
89
|
-
results << if result == ::CSpec::DataType.convert(spec[:expected])
|
90
|
-
Result.new(spec[:name], spec[:class], spec[:method], nil, spec[:description], nil)
|
91
|
-
else
|
92
|
-
Result.new(spec[:name], spec[:class], spec[:method],
|
93
|
-
"Expected #{spec[:expected]}, got: #{result}", spec[:description], nil)
|
94
|
-
end
|
95
|
-
rescue StandardError => e
|
96
|
-
results << Result.new(spec[:name], spec[:class], spec[:method], e.inspect, spec[:description], nil)
|
97
|
-
end
|
98
|
-
results
|
48
|
+
input.to_s
|
99
49
|
end
|
100
50
|
end
|
101
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarrod Folino
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,8 +59,11 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".github/workflows/ruby.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- ".rubocop_todo.yml"
|
64
67
|
- CODE_OF_CONDUCT.md
|
65
68
|
- Gemfile
|
66
69
|
- Gemfile.lock
|
@@ -70,9 +73,23 @@ files:
|
|
70
73
|
- bin/console
|
71
74
|
- bin/setup
|
72
75
|
- cspec.gemspec
|
76
|
+
- examples/basic/Gemfile
|
77
|
+
- examples/basic/Gemfile.lock
|
78
|
+
- examples/basic/myspec.rb
|
79
|
+
- examples/basic/specs.csv
|
80
|
+
- examples/class_methods/Gemfile
|
81
|
+
- examples/class_methods/Gemfile.lock
|
82
|
+
- examples/class_methods/myspec.rb
|
83
|
+
- examples/class_methods/specs.csv
|
84
|
+
- examples/method_args/Gemfile
|
85
|
+
- examples/method_args/Gemfile.lock
|
86
|
+
- examples/method_args/myspec.rb
|
87
|
+
- examples/method_args/specs.csv
|
73
88
|
- lib/cspec.rb
|
89
|
+
- lib/cspec/loader.rb
|
90
|
+
- lib/cspec/result.rb
|
91
|
+
- lib/cspec/runner.rb
|
74
92
|
- lib/cspec/version.rb
|
75
|
-
- lib/result.rb
|
76
93
|
homepage: https://github.com/jarroddalefolino/cspec
|
77
94
|
licenses:
|
78
95
|
- MIT
|
@@ -86,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
103
|
requirements:
|
87
104
|
- - ">="
|
88
105
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
106
|
+
version: 2.5.0
|
90
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
108
|
requirements:
|
92
109
|
- - ">="
|