cspec 0.2.0 → 0.2.3

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: cda46241abf4da89965884153263bde46dca2f2861f260797ae0d7e0dd9112f5
4
- data.tar.gz: c313da5f4b11eba2dc9f666d39377ae2c5d53780dfbf3a7521c97b16d02cd8d0
3
+ metadata.gz: 33a7923727e5bed051ce65388598a0312fa182a1126d8918e4e1229209853642
4
+ data.tar.gz: 203ff7ba672c258a6858a29d7f6ccdb5121708198ac91ac20eb8eea1bca14119
5
5
  SHA512:
6
- metadata.gz: a31c47d67801b6e6efd5e7ad7903e3bdec312c8df734e84768b27f707f6a89c3b0b14545c14d8450416afc3d331647fe209b3094652a68b690abb02405afcb30
7
- data.tar.gz: 6132fb403d49a14b014ffeade47400dc2c2e1c95e207573e64d50acae0bdfcab40f7fe9e6e2891ae2b563a415bd818177c89a86dce4f97a286cad93efd9cdb7b
6
+ metadata.gz: 0556b01b0fa012e11b77376c9746303927b4e595b8e9b236ac2134ee56a341c2d16ebd84f53c1665041dc1626b7a07c069b0b27c9cef28a1472ba7874e2f3437
7
+ data.tar.gz: 57307e7c92ac8129f7c1309bc7eb3db87b6bfba6ff9a5e01cbf70510511121d36402bcc1b87f0fd3f22dc18d550e3d47a9cf193b10d1bd51daa684aaea08ac79
@@ -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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cspec (0.1.5)
4
+ cspec (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.1.4)
4
+ cspec (0.2.1)
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,greent,Bob,Jones,"Hello, Bo 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.1.4)
4
+ cspec (0.2.1)
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,4 @@
1
- class,name,type,method,method_args_1,expected
2
- MyClass,my test,instance,hello,,world
1
+ class,name,type,method,expected
2
+ MyClass,my test,instance,hello,world
3
+ MyClass,my test,instance,ok?,true
4
+
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.1.4)
4
+ cspec (0.2.1)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
@@ -1,3 +1,3 @@
1
- class,name,type,method,method_args_1,expected
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"
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- cspec (0.1.4)
4
+ cspec (0.2.1)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
@@ -15,6 +15,8 @@ module CSpec
15
15
  return input.to_f if input =~ /^\d+\.\d+$/
16
16
  return input.to_i if input =~ /^\d+$/
17
17
  return eval(input) if input =~ /^\[.*\]$/
18
+ return true if input == 'true'
19
+ return false if input == 'false'
18
20
  return nil if ['', nil, 'nil'].include?(input)
19
21
 
20
22
  input.to_s
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) }
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,12 +3,11 @@
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)
@@ -27,5 +26,10 @@ module CSpec
27
26
  Result.from_spec(spec, e.inspect)
28
27
  end
29
28
  end
29
+
30
+ def self.process_errors(errors)
31
+ puts errors unless errors.empty?
32
+ !errors.empty?
33
+ end
30
34
  end
31
35
  end
data/lib/cspec/spec.rb CHANGED
@@ -29,8 +29,16 @@ module CSpec
29
29
  initialization_args == other.initialization_args
30
30
  end
31
31
 
32
+ def error
33
+ return "#{self.class} does not exist" unless Object.const_defined?(self.class)
34
+
35
+ return "#{type} method: #{method} does not exist" unless Object.const_get(self.class).method_defined?(method)
36
+
37
+ nil
38
+ end
39
+
32
40
  def to_s
33
- "name: #{name}, class: #{self.class}, method: #{method},"
41
+ "name: #{name}, class: #{self.class}, method: #{method}, method_args: #{method_args}"
34
42
  end
35
43
  end
36
44
  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?)
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.0'
3
+ module CSpec
4
+ VERSION = '0.2.3'
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.0
4
+ version: 0.2.3
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