m-spec 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -4
- data/exe/m-spec +21 -4
- data/lib/m-spec.rb +2 -0
- data/lib/m-spec/core/helpers/readable.rb +7 -5
- data/lib/m-spec/core/spec_example.rb +26 -0
- data/lib/m-spec/core/spec_result.rb +2 -2
- data/lib/m-spec/core/specs.rb +35 -0
- data/lib/m-spec/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f055e58c3c0edff2cede566c4eb387246d69b4ee536773ad95addb2b52e6074b
|
4
|
+
data.tar.gz: 58c017bc787dbeefc2411e4131b0681ca1be035ec1bc1d0c9b08765d1e010588
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a4861aebb496805aa16426fa16c6d1fb0fd1f555aa2118946eb03ee5227eece185f0e528eb4433cd9ce81d64bd3c61ccfc0e1bb581d253b9fb6a1b1a5ceba03
|
7
|
+
data.tar.gz: '082a188d2374df2fb7af946b27e346828b26990166edd2dfbf655ed300dd1d2910559adcaff0f6cb71dc350e8ce7d11bc6c2e85b60dca9f6e8d04ad5b106bd21'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Mspec
|
2
2
|
|
3
|
-
The lightest-weight spec framework in ruby. Built for learning at [Makers](https://makers.tech). You have
|
3
|
+
The lightest-weight spec framework in ruby. Built for learning at [Makers](https://makers.tech). You have two matchers, an equality matcher and an output matcher, and test setup and teardown is your responsibility. For additional features, you must extend the gem.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -43,19 +43,32 @@ describe 'The Animal' do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe '
|
47
|
-
it '
|
46
|
+
describe 'test doubles' do
|
47
|
+
it 'can be stubbed' do
|
48
48
|
mock = test_double
|
49
49
|
allow(mock).to receive(:speak) { 'Hello!' }
|
50
50
|
expect(mock.speak).to eq 'Hello!'
|
51
51
|
end
|
52
|
+
it 'can have optional names' do
|
53
|
+
mock = test_double('a name')
|
54
|
+
allow(mock).to receive(:speak) { 'Hello!' }
|
55
|
+
expect(mock.speak).to eq 'Hello!'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'testing output' do
|
60
|
+
it 'captures strings' do
|
61
|
+
expect { puts('hello') }.to output("hello\n")
|
62
|
+
end
|
52
63
|
end
|
53
64
|
```
|
54
65
|
|
55
|
-
To run your specs, pass the spec file directly as an argument. You have to run individual spec files.
|
66
|
+
To run your specs, pass the spec file directly as an argument. You have to run individual spec files, or create a file that requires your specs.
|
56
67
|
|
57
68
|
```sh
|
58
69
|
$ m-spec ./spec/animal_spec.rb
|
70
|
+
# or
|
71
|
+
$ m-spec ./spec_runner.rb
|
59
72
|
```
|
60
73
|
|
61
74
|
```
|
@@ -67,6 +80,11 @@ The Animal
|
|
67
80
|
# /path/to/directory/spec/animal_spec.rb:11:in `block (2 levels) in <top (required)>'
|
68
81
|
stubbing
|
69
82
|
we can mock too!
|
83
|
+
|
84
|
+
Inspecting 3 files
|
85
|
+
...
|
86
|
+
|
87
|
+
3 files inspected, no offenses detected
|
70
88
|
```
|
71
89
|
|
72
90
|
It's got simple one-level indentation, simple colour coding for test passes and failures, and simple failure messages with expected and actual values and the failing spec file path and line number.
|
data/exe/m-spec
CHANGED
@@ -2,16 +2,33 @@
|
|
2
2
|
require 'm-spec'
|
3
3
|
|
4
4
|
def run_rubocop!
|
5
|
-
|
6
|
-
|
5
|
+
# needs default
|
6
|
+
if File.exists?('.rubocop.yml')
|
7
|
+
puts "\n---Readability Tests---\n\n"
|
8
|
+
system("bundle exec rubocop")
|
9
|
+
else
|
10
|
+
puts "ERROR: No '.rubocop.yml' found, please create one at your project root or re-initialize m-spec with `m-spec --init`"
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
def run_specs!
|
10
15
|
spec_file = ARGV[0]
|
11
|
-
|
16
|
+
Mspec::Specs.new(spec_file).run!
|
12
17
|
end
|
13
18
|
|
14
|
-
if
|
19
|
+
if ARGV[0] == '--init'
|
20
|
+
contents = File.read("#{ENV['GEM_HOME']}/gems/m-spec-#{Mspec::VERSION}/.rubocop.yml")
|
21
|
+
File.open('.rubocop.yml', 'w') do |file|
|
22
|
+
file.write(contents)
|
23
|
+
end
|
24
|
+
puts 'created: .rubocop.yml'
|
25
|
+
|
26
|
+
contents = "# This has been auto-generated. Feel free to delete these comments.\n#\n# Try adding options below: '--no-rubocop' or '--only-rubocop' without the quotes."
|
27
|
+
File.open('.m-spec', 'w') do |file|
|
28
|
+
file.write(contents)
|
29
|
+
end
|
30
|
+
puts 'created: .m-spec'
|
31
|
+
elsif File.exists?('./.m-spec')
|
15
32
|
File.open('./.m-spec', 'r') do |file|
|
16
33
|
options = file.read.split
|
17
34
|
if options.include?('--only-rubocop')
|
data/lib/m-spec.rb
CHANGED
@@ -5,6 +5,8 @@ require "m-spec/version"
|
|
5
5
|
require "m-spec/core/expect"
|
6
6
|
require "m-spec/core/spec_error"
|
7
7
|
require "m-spec/core/spec_result"
|
8
|
+
require "m-spec/core/spec_example"
|
9
|
+
require "m-spec/core/specs"
|
8
10
|
require "m-spec/core/matchers/equal"
|
9
11
|
require "m-spec/core/matchers/output"
|
10
12
|
require "m-spec/core/helpers/readable"
|
@@ -9,16 +9,18 @@ def describe(str)
|
|
9
9
|
yield
|
10
10
|
end
|
11
11
|
|
12
|
-
def it(str)
|
13
|
-
|
14
|
-
|
12
|
+
def it(str, specs = Mspec::Specs.instance)
|
13
|
+
spec_example = Mspec::SpecExample.new(str, yield)
|
14
|
+
specs.add(spec_example)
|
15
|
+
|
16
|
+
if spec_example.success?
|
15
17
|
puts " \e[#{COLOUR_CODES[:green]}m#{str}\e[0m"
|
16
18
|
else
|
17
19
|
puts " \e[#{COLOUR_CODES[:red]}m#{str}\e[0m"
|
18
|
-
|
20
|
+
spec_example.failure_message.each do |line|
|
19
21
|
puts " \e[#{COLOUR_CODES[:red]}m#{line}\e[0m"
|
20
22
|
end
|
21
|
-
puts " \e[#{COLOUR_CODES[:light_blue]}m# #{
|
23
|
+
puts " \e[#{COLOUR_CODES[:light_blue]}m# #{spec_example.trace}\e[0m"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mspec
|
2
|
+
class SpecExample
|
3
|
+
attr_reader :description, :result
|
4
|
+
|
5
|
+
def initialize(description, result)
|
6
|
+
@description = description
|
7
|
+
@result = result
|
8
|
+
end
|
9
|
+
|
10
|
+
def success?
|
11
|
+
@result.success?
|
12
|
+
end
|
13
|
+
|
14
|
+
def failure?
|
15
|
+
!success?
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message
|
19
|
+
@result.failure_message
|
20
|
+
end
|
21
|
+
|
22
|
+
def trace
|
23
|
+
@result.trace
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -12,8 +12,8 @@ module Mspec
|
|
12
12
|
|
13
13
|
def failure_message
|
14
14
|
[
|
15
|
-
"Expected: #{@expected_result.value.inspect}",
|
16
|
-
"Got: #{test_code_result.inspect}",
|
15
|
+
"Expected: ".rjust(9) + "#{@expected_result.value.inspect}",
|
16
|
+
"Got: ".rjust(9) + "#{test_code_result.inspect}",
|
17
17
|
]
|
18
18
|
end
|
19
19
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Mspec
|
2
|
+
class Specs
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
def initialize(file)
|
6
|
+
@file = file
|
7
|
+
@data = []
|
8
|
+
@@instance = self
|
9
|
+
end
|
10
|
+
|
11
|
+
def run!
|
12
|
+
require(@file)
|
13
|
+
summary
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(spec)
|
17
|
+
@data << spec
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.instance
|
21
|
+
@@instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def summary
|
25
|
+
puts "\n---Summary---\n\n"
|
26
|
+
puts "#{@data.length} examples found"
|
27
|
+
failures = @data.select(&:failure?)
|
28
|
+
|
29
|
+
puts "#{failures.length} failures"
|
30
|
+
failures.each_with_index do |spec, index|
|
31
|
+
puts " \e[#{COLOUR_CODES[:red]}m#{index+1}. #{spec.trace}\e[0m"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/m-spec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edward Withers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -77,7 +77,9 @@ files:
|
|
77
77
|
- lib/m-spec/core/matchers/equal.rb
|
78
78
|
- lib/m-spec/core/matchers/output.rb
|
79
79
|
- lib/m-spec/core/spec_error.rb
|
80
|
+
- lib/m-spec/core/spec_example.rb
|
80
81
|
- lib/m-spec/core/spec_result.rb
|
82
|
+
- lib/m-spec/core/specs.rb
|
81
83
|
- lib/m-spec/mocks/allow.rb
|
82
84
|
- lib/m-spec/mocks/helpers/readable.rb
|
83
85
|
- lib/m-spec/mocks/mock.rb
|