cspec 0.1.5 → 0.2.2
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 +0 -3
- data/.rubocop_todo.yml +1 -17
- data/Gemfile.lock +9 -1
- data/cspec.gemspec +2 -1
- data/examples/advance/Gemfile +4 -0
- data/examples/advance/Gemfile.lock +13 -0
- data/examples/advance/myspec.rb +33 -0
- data/examples/advance/specs.csv +6 -0
- data/examples/basic/Gemfile.lock +1 -1
- data/examples/basic/myspec.rb +4 -0
- data/examples/basic/specs.csv +11 -1
- data/examples/class_methods/Gemfile.lock +1 -1
- data/examples/class_methods/specs.csv +2 -2
- data/examples/method_args/Gemfile.lock +1 -1
- data/lib/cspec/code_exec.rb +25 -0
- data/lib/cspec/data_type.rb +23 -0
- data/lib/cspec/loader.rb +6 -5
- data/lib/cspec/result.rb +8 -17
- data/lib/cspec/results_outputter.rb +11 -0
- data/lib/cspec/runner.rb +3 -3
- data/lib/cspec/spec.rb +36 -0
- data/lib/cspec/validator.rb +11 -0
- data/lib/cspec/version.rb +2 -2
- data/lib/cspec.rb +4 -40
- metadata +25 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04fe4315cc0239fbba40d3b9161a2a611ba9e5199530020dd3111904969a063
|
4
|
+
data.tar.gz: f79b42125b163718b31b525c7dbaab2358e774b46ab4ac40f1bf82fe575ee252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3427855f23bc9f089a938454ec8c21c2220f6ea27fbcce4707930fa2c40674cf5df7a1277dc7ed574687bbe7d70b53d8b05a732236c85581b2077dd8e9fbc785
|
7
|
+
data.tar.gz: 5e50f436086bf34ad3e0de488e231f87ec2fe07b8cb8f8eaa79c89b28a3333b4f74afbe0dcd6cf034b593d8907f9b24d58086db37341e8bc6b6023b343e04c8d
|
data/.github/workflows/ruby.yml
CHANGED
@@ -24,9 +24,6 @@ jobs:
|
|
24
24
|
steps:
|
25
25
|
- uses: actions/checkout@v2
|
26
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
27
|
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
28
|
with:
|
32
29
|
ruby-version: ${{ matrix.ruby-version }}
|
data/.rubocop_todo.yml
CHANGED
@@ -1,28 +1,12 @@
|
|
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
1
|
Metrics/BlockLength:
|
13
2
|
Max: 50
|
14
3
|
|
15
|
-
# Offense count: 1
|
16
|
-
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
17
4
|
Metrics/MethodLength:
|
18
5
|
Max: 11
|
19
6
|
|
20
|
-
# Offense count: 1
|
21
|
-
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
22
7
|
Metrics/ParameterLists:
|
23
8
|
Max: 6
|
24
9
|
|
25
|
-
# Offense count: 1
|
26
10
|
Security/Eval:
|
27
11
|
Exclude:
|
28
|
-
- 'lib/cspec.rb'
|
12
|
+
- 'lib/cspec/data_type.rb'
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cspec (0.1
|
4
|
+
cspec (0.2.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.5.0)
|
10
|
+
docile (1.4.0)
|
10
11
|
rake (10.5.0)
|
11
12
|
rspec (3.11.0)
|
12
13
|
rspec-core (~> 3.11.0)
|
@@ -21,6 +22,12 @@ GEM
|
|
21
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
23
|
rspec-support (~> 3.11.0)
|
23
24
|
rspec-support (3.11.0)
|
25
|
+
simplecov (0.21.2)
|
26
|
+
docile (~> 1.1)
|
27
|
+
simplecov-html (~> 0.11)
|
28
|
+
simplecov_json_formatter (~> 0.1)
|
29
|
+
simplecov-html (0.12.3)
|
30
|
+
simplecov_json_formatter (0.1.4)
|
24
31
|
|
25
32
|
PLATFORMS
|
26
33
|
ruby
|
@@ -30,6 +37,7 @@ DEPENDENCIES
|
|
30
37
|
cspec!
|
31
38
|
rake (~> 10.0)
|
32
39
|
rspec (~> 3.0)
|
40
|
+
simplecov
|
33
41
|
|
34
42
|
BUNDLED WITH
|
35
43
|
1.17.2
|
data/cspec.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'cspec/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.required_ruby_version = '>= 2.5.0'
|
9
9
|
spec.name = 'cspec'
|
10
|
-
spec.version =
|
10
|
+
spec.version = CSpec::VERSION
|
11
11
|
spec.authors = ['Jarrod Folino']
|
12
12
|
spec.email = ['jarrod.folino@coderacademy.edu.au']
|
13
13
|
|
@@ -41,4 +41,5 @@ Gem::Specification.new do |spec|
|
|
41
41
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
42
42
|
spec.add_development_dependency 'rake', '~> 10.0'
|
43
43
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
44
|
+
spec.add_development_dependency 'simplecov'
|
44
45
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cspec'
|
4
|
+
|
5
|
+
class MyClass
|
6
|
+
def greet(fname, sname)
|
7
|
+
"Hello, #{fname} #{sname}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Util
|
12
|
+
def build_array(val1, val2, val3)
|
13
|
+
[val1, val2, val3]
|
14
|
+
end
|
15
|
+
|
16
|
+
def sum_array(array)
|
17
|
+
array.sum
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Calculator
|
22
|
+
def self.add(val1, val2)
|
23
|
+
val1 + val2
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.multi_subtract(val1, val2, val3)
|
27
|
+
val1 - val2 - val3
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
result = CSpec::Runner.run!("#{Dir.pwd}/specs.csv")
|
32
|
+
puts "Success: #{result}"
|
33
|
+
exit result ? 0 : 1
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class,name,type,method,method_arg_1,method_arg_2,method_arg_3,expected
|
2
|
+
MyClass,my test,instance,greet,Bob,Jones,,"Hello, Bob Jones"
|
3
|
+
Calculator,another test,class,add,1,2,,3
|
4
|
+
Calculator,another test,class,multi_subtract,6,2,1,3
|
5
|
+
Util,another test,instance,build_array,6,2,1,"[6, 2, 1]"
|
6
|
+
Util,another test,instance,sum_array,"[6, 2, 1]",,,9
|
data/examples/basic/Gemfile.lock
CHANGED
data/examples/basic/myspec.rb
CHANGED
data/examples/basic/specs.csv
CHANGED
@@ -1,2 +1,12 @@
|
|
1
|
-
class,name,type,method,
|
1
|
+
class,name,type,method,method_arg_1,expected
|
2
|
+
MyClass,my test,instance,hello2,aaa,world2aaa
|
2
3
|
MyClass,my test,instance,hello,,world
|
4
|
+
MyClass,my test,instance,hello2,aaa,world2aaa
|
5
|
+
MyClass,my test,instance,hello,,world
|
6
|
+
MyClass,my test,instance,hello2,aaa,world2aaa
|
7
|
+
MyClass,my test,instance,hello,,world
|
8
|
+
MyClass,my test,instance,hello2,aaa,world2aaa
|
9
|
+
MyClass,my test,instance,hello,,world
|
10
|
+
MyClass,my test,instance,hello2,aaa,world2aaa
|
11
|
+
MyClass,my test,instance,hello,,world
|
12
|
+
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class,name,type,method,
|
1
|
+
class,name,type,method,method_arg_1,expected
|
2
2
|
MyClass,my test,class,hello,,world
|
3
|
-
MyClass,my test,class,say,Bob,"Hello, Bob"
|
3
|
+
MyClass,my test,class,say,"Bob","Hello, Bob"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CSpec
|
4
|
+
module CodeExec
|
5
|
+
def self.do_instance(spec)
|
6
|
+
class_under_test = Object.const_get(spec.class)
|
7
|
+
instance_under_test = class_under_test.new(*spec.initialization_args)
|
8
|
+
instance_under_test.send(spec.method, *spec.method_args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.do_class(spec)
|
12
|
+
class_under_test = Object.const_get(spec.class)
|
13
|
+
class_under_test.send(spec.method, *spec.method_args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.do(spec)
|
17
|
+
case spec.type
|
18
|
+
when 'class'
|
19
|
+
do_class(spec)
|
20
|
+
when 'instance'
|
21
|
+
do_instance(spec)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CSpec
|
4
|
+
module DataType
|
5
|
+
def self.convert_all(inputs)
|
6
|
+
return nil unless inputs
|
7
|
+
|
8
|
+
inputs.map { |input| convert(input) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.convert(input)
|
12
|
+
return input unless input.instance_of?(String)
|
13
|
+
|
14
|
+
input = input.strip
|
15
|
+
return input.to_f if input =~ /^\d+\.\d+$/
|
16
|
+
return input.to_i if input =~ /^\d+$/
|
17
|
+
return eval(input) if input =~ /^\[.*\]$/
|
18
|
+
return nil if ['', nil, 'nil'].include?(input)
|
19
|
+
|
20
|
+
input.to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/cspec/loader.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'spec'
|
4
|
+
|
3
5
|
module CSpec
|
4
6
|
module Loader
|
5
7
|
def self.load(filename)
|
6
|
-
::CSV.open(filename, headers: :first_row).map(&:to_h)
|
8
|
+
specs = ::CSV.open(filename, headers: :first_row).map(&:to_h)
|
9
|
+
specs.map { |spec| ::CSpec::Spec.new(process_args(spec)) }
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.process_args(spec)
|
@@ -15,16 +18,14 @@ module CSpec
|
|
15
18
|
def self.process_arg(spec, regex, aggregate_key)
|
16
19
|
spec.merge({
|
17
20
|
aggregate_key => spec.keys
|
18
|
-
.select { |k| k.match?(regex) }
|
21
|
+
.select { |k| k.match?(regex) && !spec[k].nil? }
|
19
22
|
.inject([]) { |values, key| values << spec[key] }
|
20
23
|
})
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.validate(filename)
|
24
27
|
headers = CSV.open(filename, &:readline)
|
25
|
-
|
26
|
-
"Need header: #{required_header}" unless headers.include?(required_header)
|
27
|
-
end.reject(&:nil?)
|
28
|
+
::CSpec::Validator.validate(headers)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
data/lib/cspec/result.rb
CHANGED
@@ -2,38 +2,29 @@
|
|
2
2
|
|
3
3
|
module CSpec
|
4
4
|
class Result
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :spec, :error
|
6
6
|
|
7
7
|
def self.success?(results)
|
8
8
|
results.count { |r| !r.error.nil? }.zero?
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.from_spec(spec, error = nil)
|
12
|
-
Result.new(spec
|
13
|
-
error, spec['description'], nil)
|
12
|
+
Result.new(spec, error)
|
14
13
|
end
|
15
14
|
|
16
|
-
def initialize(
|
17
|
-
@
|
15
|
+
def initialize(spec, error)
|
16
|
+
@spec = spec
|
18
17
|
@error = error
|
19
|
-
@class = klass
|
20
|
-
@method = method
|
21
|
-
@description = description
|
22
|
-
@details = details
|
23
18
|
end
|
24
19
|
|
25
20
|
def ==(other)
|
26
|
-
|
27
|
-
|
28
|
-
method == other.method &&
|
29
|
-
error == other.error &&
|
30
|
-
description == other.description &&
|
31
|
-
details == other.details
|
21
|
+
error == other.error &&
|
22
|
+
spec == other.spec
|
32
23
|
end
|
33
24
|
|
34
25
|
def to_s
|
35
|
-
"
|
36
|
-
"
|
26
|
+
"spec: #{spec}\n" \
|
27
|
+
"error: #{error}"
|
37
28
|
end
|
38
29
|
end
|
39
30
|
end
|
data/lib/cspec/runner.rb
CHANGED
@@ -19,9 +19,9 @@ module CSpec
|
|
19
19
|
|
20
20
|
def self.run(specs)
|
21
21
|
specs.map do |spec|
|
22
|
-
result = ::CSpec::
|
23
|
-
expected = ::CSpec::DataType.convert(spec
|
24
|
-
error_msg = "Expected #{spec
|
22
|
+
result = ::CSpec::CodeExec.do(spec)
|
23
|
+
expected = ::CSpec::DataType.convert(spec.expected)
|
24
|
+
error_msg = "Expected #{spec.expected}, got: #{result}" if result != expected
|
25
25
|
Result.from_spec(spec, error_msg)
|
26
26
|
rescue StandardError => e
|
27
27
|
Result.from_spec(spec, e.inspect)
|
data/lib/cspec/spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CSpec
|
4
|
+
class Spec
|
5
|
+
attr_reader :class,
|
6
|
+
:name,
|
7
|
+
:type,
|
8
|
+
:method,
|
9
|
+
:method_args,
|
10
|
+
:initialization_args,
|
11
|
+
:expected
|
12
|
+
|
13
|
+
def initialize(hash)
|
14
|
+
@class = hash['class']
|
15
|
+
@name = hash['name']
|
16
|
+
@type = hash['type']
|
17
|
+
@method = hash['method']
|
18
|
+
@method_args = ::CSpec::DataType.convert_all(hash['method_args'])
|
19
|
+
@initialization_args = ::CSpec::DataType.convert_all(hash['initialization_args'])
|
20
|
+
@expected = hash['expected']
|
21
|
+
end
|
22
|
+
|
23
|
+
def ==(other)
|
24
|
+
name == other.name &&
|
25
|
+
self.class == other.class &&
|
26
|
+
method == other.method &&
|
27
|
+
type == other.type &&
|
28
|
+
method_args == other.method_args &&
|
29
|
+
initialization_args == other.initialization_args
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"name: #{name}, class: #{self.class}, method: #{method},"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CSpec
|
4
|
+
module Validator
|
5
|
+
def self.validate(headers)
|
6
|
+
%w[class type name method expected].map do |required_header|
|
7
|
+
"Need header: #{required_header}" unless headers.include?(required_header)
|
8
|
+
end.reject(&:nil?)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/cspec/version.rb
CHANGED
data/lib/cspec.rb
CHANGED
@@ -4,48 +4,12 @@ require 'cspec/version'
|
|
4
4
|
require 'cspec/runner'
|
5
5
|
require 'cspec/loader'
|
6
6
|
require 'cspec/result'
|
7
|
+
require 'cspec/code_exec'
|
8
|
+
require 'cspec/data_type'
|
9
|
+
require 'cspec/validator'
|
10
|
+
require 'cspec/results_outputter'
|
7
11
|
|
8
12
|
require 'csv'
|
9
13
|
|
10
14
|
module CSpec
|
11
|
-
module ResultsOutputter
|
12
|
-
def self.display(results)
|
13
|
-
results.each do |r|
|
14
|
-
puts r
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module Executer
|
20
|
-
def self.do_instance(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'])
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.do_class(spec)
|
27
|
-
class_under_test = Object.const_get(spec['class'])
|
28
|
-
class_under_test.send(spec['method'], *spec['method_args'])
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.do(spec)
|
32
|
-
case spec[:type]
|
33
|
-
when 'class'
|
34
|
-
do_class(spec)
|
35
|
-
when 'instance'
|
36
|
-
do_instance(spec)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
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)
|
47
|
-
|
48
|
-
input.to_s
|
49
|
-
end
|
50
|
-
end
|
51
15
|
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.
|
4
|
+
version: 0.2.2
|
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-03-
|
11
|
+
date: 2022-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A testing framework to run unit tests via csv
|
56
70
|
email:
|
57
71
|
- jarrod.folino@coderacademy.edu.au
|
@@ -73,6 +87,10 @@ files:
|
|
73
87
|
- bin/console
|
74
88
|
- bin/setup
|
75
89
|
- cspec.gemspec
|
90
|
+
- examples/advance/Gemfile
|
91
|
+
- examples/advance/Gemfile.lock
|
92
|
+
- examples/advance/myspec.rb
|
93
|
+
- examples/advance/specs.csv
|
76
94
|
- examples/basic/Gemfile
|
77
95
|
- examples/basic/Gemfile.lock
|
78
96
|
- examples/basic/myspec.rb
|
@@ -86,9 +104,14 @@ files:
|
|
86
104
|
- examples/method_args/myspec.rb
|
87
105
|
- examples/method_args/specs.csv
|
88
106
|
- lib/cspec.rb
|
107
|
+
- lib/cspec/code_exec.rb
|
108
|
+
- lib/cspec/data_type.rb
|
89
109
|
- lib/cspec/loader.rb
|
90
110
|
- lib/cspec/result.rb
|
111
|
+
- lib/cspec/results_outputter.rb
|
91
112
|
- lib/cspec/runner.rb
|
113
|
+
- lib/cspec/spec.rb
|
114
|
+
- lib/cspec/validator.rb
|
92
115
|
- lib/cspec/version.rb
|
93
116
|
homepage: https://github.com/jarroddalefolino/cspec
|
94
117
|
licenses:
|