cspec 0.2.1 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8614fd567ad97eaea1795b6784a114231372e2a06958ed27ab8159b1826df43d
4
- data.tar.gz: 8232cd508d0bb084224329b08fdbe9fe036887a293a5441576c0c9abf9481b9c
3
+ metadata.gz: 4de36af904dcb6411a59838e1ed2f415bbf82103db8bdaad599c6be4f3afc5e1
4
+ data.tar.gz: 19da5e138539e167c6084040eea3c1ef5e165e833d56e2cc0e15960f24c824d8
5
5
  SHA512:
6
- metadata.gz: 831a347acc12b8ac8a5f81af9f426f3bd6a9730818406c5303bb41b2e67b3b21e6354112dd361eae91917db677be0a1499b355b33e1627bab70da13b38bc8887
7
- data.tar.gz: 10132f08dd3fe64a7f14406adcecee1c3374e5988f94562387ceec35aa7043877c8713761900e2e9a4acb7c87f3aefb0f255282a13406c530478eebbb0511252
6
+ metadata.gz: 558cad6ce6e23b6519c3d78cf518c4d49d6554e680ca9a7cfc5187eaa1eab52a57a5c386e23b2b6ebc6844feb55cb8dd24e1f87c97af262c0430aece81683a9b
7
+ data.tar.gz: 2a31cc1c832f7e65fedacb7047a6e178065ff3675ddf5e190bb31f6c20f60135d036df8c1cec5376bae044e2be3dbbe7d7845697cd607417e34eeea6778bd787
data/Gemfile.lock CHANGED
@@ -1,13 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cspec (0.2.0)
4
+ cspec (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ coderay (1.1.3)
9
10
  diff-lcs (1.5.0)
10
11
  docile (1.4.0)
12
+ method_source (1.0.0)
13
+ pry (0.14.1)
14
+ coderay (~> 1.1)
15
+ method_source (~> 1.0)
11
16
  rake (10.5.0)
12
17
  rspec (3.11.0)
13
18
  rspec-core (~> 3.11.0)
@@ -35,6 +40,7 @@ PLATFORMS
35
40
  DEPENDENCIES
36
41
  bundler (~> 1.17)
37
42
  cspec!
43
+ pry
38
44
  rake (~> 10.0)
39
45
  rspec (~> 3.0)
40
46
  simplecov
data/README.md CHANGED
@@ -12,7 +12,7 @@ The goal of this project is to have a centralised location where all specs can b
12
12
  ```
13
13
  * Create a CSV named `specs.csv` with the following spec
14
14
  ```csv
15
- class,name,type,initialize_params_1,method,method_args_1,expected
15
+ class,name,type,initialization_arg_1,method,method_arg_1,expected
16
16
  MyClass,my test,,hello,,world
17
17
  ```
18
18
  * Create a file named `my_csv_specs.rb` to run the specs
@@ -31,4 +31,4 @@ result = CSpec::Runner.run!("#{Dir.pwd}/specs.csv")
31
31
  puts "Success: #{result}"
32
32
  ```
33
33
 
34
- * Run with `ruby my_csv_specs.rb`
34
+ * Run with `ruby my_csv_specs.rb`
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 = Cspec::VERSION
10
+ spec.version = CSpec::VERSION
11
11
  spec.authors = ['Jarrod Folino']
12
12
  spec.email = ['jarrod.folino@coderacademy.edu.au']
13
13
 
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.require_paths = ['lib']
40
40
 
41
41
  spec.add_development_dependency 'bundler', '~> 1.17'
42
+ spec.add_development_dependency 'pry'
42
43
  spec.add_development_dependency 'rake', '~> 10.0'
43
44
  spec.add_development_dependency 'rspec', '~> 3.0'
44
45
  spec.add_development_dependency 'simplecov'
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.2.0)
4
+ cspec (0.2.3)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
@@ -8,6 +8,26 @@ class MyClass
8
8
  end
9
9
  end
10
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
+
11
31
  result = CSpec::Runner.run!("#{Dir.pwd}/specs.csv")
12
32
  puts "Success: #{result}"
13
33
  exit result ? 0 : 1
@@ -1,2 +1,6 @@
1
- class,name,type,method,method_arg_1,method_arg_2,expected
2
- MyClass,my test,instance,greet,Bob,Jones,"Hello, Bob Jones"
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
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.2.0)
4
+ cspec (0.2.3)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
@@ -6,6 +6,10 @@ class MyClass
6
6
  def hello
7
7
  'world'
8
8
  end
9
+
10
+ def ok?
11
+ true
12
+ end
9
13
  end
10
14
 
11
15
  result = CSpec::Runner.run!("#{Dir.pwd}/specs.csv")
@@ -1,2 +1,3 @@
1
1
  class,name,type,method,expected
2
2
  MyClass,my test,instance,hello,world
3
+ MyClass,my test,instance,ok?,true
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.2.0)
4
+ cspec (0.2.3)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.2.0)
4
+ cspec (0.2.1)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
@@ -2,6 +2,16 @@
2
2
 
3
3
  module CSpec
4
4
  module DataType
5
+ MATCHERS = [
6
+ { condition: /^\d+\.\d+$/, proc: proc { |input| input.to_f } },
7
+ { condition: /^\d+$/, proc: proc { |input| input.to_i } },
8
+ { condition: /true/, proc: proc { true } },
9
+ { condition: /^\[.*\]$/, proc: proc { |input| eval(input) } },
10
+ { condition: /false/, proc: proc { false } },
11
+ { condition: /nil/, proc: proc { nil } },
12
+ { condition: /^$/, proc: proc { nil } }
13
+ ].freeze
14
+
5
15
  def self.convert_all(inputs)
6
16
  return nil unless inputs
7
17
 
@@ -12,10 +22,9 @@ module CSpec
12
22
  return input unless input.instance_of?(String)
13
23
 
14
24
  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)
25
+ MATCHERS.each do |matcher|
26
+ return matcher[:proc].call(input) if input.match?(matcher[:condition])
27
+ end
19
28
 
20
29
  input.to_s
21
30
  end
data/lib/cspec/loader.rb CHANGED
@@ -18,14 +18,14 @@ module CSpec
18
18
  def self.process_arg(spec, regex, aggregate_key)
19
19
  spec.merge({
20
20
  aggregate_key => spec.keys
21
- .select { |k| k.match?(regex) && spec[k] != nil }
21
+ .select { |k| k.match?(regex) && !spec[k].nil? }
22
22
  .inject([]) { |values, key| values << spec[key] }
23
23
  })
24
24
  end
25
25
 
26
- def self.validate(filename)
26
+ def self.validate_structure(filename)
27
27
  headers = CSV.open(filename, &:readline)
28
- ::CSpec::Validator.validate(headers)
28
+ ::CSpec::Validator.validate_structure(headers)
29
29
  end
30
30
  end
31
31
  end
data/lib/cspec/result.rb CHANGED
@@ -23,7 +23,7 @@ module CSpec
23
23
  end
24
24
 
25
25
  def to_s
26
- "spec: #{spec}\n" \
26
+ "#{spec}, " \
27
27
  "error: #{error}"
28
28
  end
29
29
  end
data/lib/cspec/runner.rb CHANGED
@@ -3,16 +3,17 @@
3
3
  module CSpec
4
4
  module Runner
5
5
  def self.run!(filepath)
6
- errors = Loader.validate(filepath)
7
- unless errors.empty?
8
- puts errors
9
- return false
10
- end
6
+ return false if process_errors(Loader.validate_structure(filepath))
7
+
11
8
  specs = Loader.load(filepath)
9
+ return false if process_errors(::CSpec::Validator.validate_specs(specs))
10
+
12
11
  results = run(specs)
13
12
 
14
13
  return true if CSpec::Result.success?(results)
15
14
 
15
+ puts results.inspect
16
+ puts '#######################'
16
17
  ResultsOutputter.display(results)
17
18
  false
18
19
  end
@@ -27,5 +28,10 @@ module CSpec
27
28
  Result.from_spec(spec, e.inspect)
28
29
  end
29
30
  end
31
+
32
+ def self.process_errors(errors)
33
+ puts errors unless errors.empty?
34
+ !errors.empty?
35
+ end
30
36
  end
31
37
  end
data/lib/cspec/spec.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pry'
3
4
  module CSpec
4
5
  class Spec
5
6
  attr_reader :class,
@@ -29,8 +30,36 @@ module CSpec
29
30
  initialization_args == other.initialization_args
30
31
  end
31
32
 
33
+ def error
34
+ return ["#{self.class} does not exist"] unless Object.const_defined?(self.class)
35
+
36
+ errors = []
37
+
38
+ errors += send("#{type}_errors")
39
+
40
+ errors.size.positive? ? errors.flatten : nil
41
+ end
42
+
32
43
  def to_s
33
- "name: #{name}, class: #{self.class}, method: #{method},"
44
+ "name: #{name}, class: #{self.class}, method: #{method}, method_args: #{method_args}"
45
+ end
46
+
47
+ private
48
+
49
+ def class_errors
50
+ if Object.const_get(self.class).respond_to?(method.to_sym)
51
+ []
52
+ else
53
+ ["#{type} method: #{self.class}##{method} does not exist"]
54
+ end
55
+ end
56
+
57
+ def instance_errors
58
+ if !Object.const_get(self.class)&.method_defined?(method.to_sym)
59
+ ["#{type} method: #{self.class}##{method} does not exist"]
60
+ else
61
+ []
62
+ end
34
63
  end
35
64
  end
36
65
  end
@@ -2,10 +2,14 @@
2
2
 
3
3
  module CSpec
4
4
  module Validator
5
- def self.validate(headers)
5
+ def self.validate_structure(headers)
6
6
  %w[class type name method expected].map do |required_header|
7
7
  "Need header: #{required_header}" unless headers.include?(required_header)
8
8
  end.reject(&:nil?)
9
9
  end
10
+
11
+ def self.validate_specs(specs)
12
+ specs.map(&:error).reject(&:nil?).flatten
13
+ end
10
14
  end
11
15
  end
data/lib/cspec/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Cspec
4
- VERSION = '0.2.1'
3
+ module CSpec
4
+ VERSION = '0.2.4'
5
5
  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.2.1
4
+ version: 0.2.4
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-06 00:00:00.000000000 Z
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement