m-spec 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -8
- data/lib/m-spec.rb +3 -0
- data/lib/m-spec/core/expect.rb +3 -1
- data/lib/m-spec/core/helpers/readable.rb +19 -9
- data/lib/m-spec/core/matchers/equal.rb +2 -0
- data/lib/m-spec/core/matchers/output.rb +31 -0
- data/lib/m-spec/core/spec_result.rb +22 -3
- data/lib/m-spec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6420629e2b27b246efaca92e6ad572603eaaf05bfaf716b0d386cadebafab8f9
|
4
|
+
data.tar.gz: 33e8d052ef1d6513a06e9048ac12ce95c51b1597c3ef7246b4d360619b304cab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9484c58fa989d6dea4c2a94abed38d2d769b04c663c3206588961d41858f3ae1c2afda4cfac94b515c9364191131b96913d335d1379765f8af495ec6da9ddba
|
7
|
+
data.tar.gz: 21ba3b262a018015878cac2b140acbde0e46ad6e916cb17de44e1a25ea4861d49478d67cd05050d354c96ac180647110b3a9937e452c86319cc3098c5ab24255
|
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).
|
3
|
+
The lightest-weight spec framework in ruby. Built for learning at [Makers](https://makers.tech). You have one matcher, the comparison matcher, and test setup and teardown is your responsibility. For additional features, you must extend the gem.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -37,7 +37,7 @@ describe 'The Animal' do
|
|
37
37
|
expect(animal.roar).to eq "ROAAAARRRR!"
|
38
38
|
end
|
39
39
|
|
40
|
-
it '
|
40
|
+
it 'fails nicely' do
|
41
41
|
animal = Animal.new
|
42
42
|
expect(animal.roar).to eq "little roar!"
|
43
43
|
end
|
@@ -62,20 +62,38 @@ $ m-spec ./spec/animal_spec.rb
|
|
62
62
|
The Animal
|
63
63
|
returns a string
|
64
64
|
fails nicely
|
65
|
-
|
65
|
+
Expected: ROAAAARRRR!
|
66
|
+
Got: little roar!
|
67
|
+
# /path/to/directory/spec/animal_spec.rb:11:in `block (2 levels) in <top (required)>'
|
66
68
|
stubbing
|
67
69
|
we can mock too!
|
68
70
|
```
|
69
71
|
|
70
|
-
It's got simple one-level indentation
|
72
|
+
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.
|
71
73
|
|
72
|
-
Remember - you'll have to manage test setup and
|
74
|
+
Remember - you'll have to manage yourself: test setup and teardown, keeping test code dry, each test running in isolation, and loading source code properly.
|
73
75
|
|
74
|
-
##
|
76
|
+
## Extending
|
75
77
|
|
76
|
-
After checking out the repo
|
78
|
+
After checking out the repo
|
79
|
+
```sh
|
80
|
+
$ git clone git@github.com:dearshrewdwit/m-spec.git
|
81
|
+
$ cd m-spec
|
82
|
+
```
|
83
|
+
Add more matchers, or extend the mocking library. Then build locally and use.
|
84
|
+
```sh
|
85
|
+
bundle exec rake build --trace
|
86
|
+
gem install pkg/m-spec-[version].gem
|
87
|
+
m-spec [spec-file]
|
88
|
+
```
|
89
|
+
|
90
|
+
## Pushing to Rubygems
|
91
|
+
Sign up for an account, check for the gem name you want, change the gem metadata to represent what you want, and then follow the hints and errors when you
|
92
|
+
```sh
|
93
|
+
$ bundle exec rake release
|
94
|
+
```
|
77
95
|
|
78
|
-
|
96
|
+
[Bundler docs](https://bundler.io/guides/creating_gem.html) are a good resource, as are the [rubygems docs](https://guides.rubygems.org/publishing/)
|
79
97
|
|
80
98
|
## Contributing
|
81
99
|
|
data/lib/m-spec.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
require "m-spec/version"
|
2
4
|
|
3
5
|
require "m-spec/core/expect"
|
4
6
|
require "m-spec/core/spec_error"
|
5
7
|
require "m-spec/core/spec_result"
|
6
8
|
require "m-spec/core/matchers/equal"
|
9
|
+
require "m-spec/core/matchers/output"
|
7
10
|
require "m-spec/core/helpers/readable"
|
8
11
|
|
9
12
|
require "m-spec/mocks/allow"
|
data/lib/m-spec/core/expect.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
COLOUR_CODES = {
|
2
|
-
|
3
|
-
|
2
|
+
green: 32,
|
3
|
+
red: 31,
|
4
|
+
light_blue: 36
|
4
5
|
}
|
5
6
|
|
6
7
|
def describe(str)
|
@@ -10,18 +11,27 @@ end
|
|
10
11
|
|
11
12
|
def it(str)
|
12
13
|
spec_result = yield
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
if spec_result.success?
|
15
|
+
puts " \e[#{COLOUR_CODES[:green]}m#{str}\e[0m"
|
16
|
+
else
|
17
|
+
puts " \e[#{COLOUR_CODES[:red]}m#{str}\e[0m"
|
18
|
+
spec_result.failure_message.each do |line|
|
19
|
+
puts " \e[#{COLOUR_CODES[:red]}m#{line}\e[0m"
|
18
20
|
end
|
21
|
+
puts " \e[#{COLOUR_CODES[:light_blue]}m# #{spec_result.trace}\e[0m"
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
25
|
+
def expect(obj=nil, &block)
|
26
|
+
if obj
|
27
|
+
Mspec::Expect.new(obj)
|
28
|
+
else
|
29
|
+
Mspec::Expect.new(block)
|
30
|
+
end
|
31
|
+
end
|
22
32
|
|
23
|
-
def
|
24
|
-
Mspec::
|
33
|
+
def output(string)
|
34
|
+
Mspec::Matchers::Output.new(string)
|
25
35
|
end
|
26
36
|
|
27
37
|
def eq(obj)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module Mspec
|
4
|
+
module Matchers
|
5
|
+
class Output
|
6
|
+
attr_reader :value, :test_code_output_string
|
7
|
+
|
8
|
+
def initialize(value)
|
9
|
+
@value = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def check(block)
|
13
|
+
output = mock_output do
|
14
|
+
block.call
|
15
|
+
end
|
16
|
+
@test_code_output_string = output.string
|
17
|
+
|
18
|
+
@value == @test_code_output_string
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def mock_output(output=StringIO.new, &block)
|
24
|
+
$stdout = output
|
25
|
+
block.call
|
26
|
+
$stdout = STDOUT
|
27
|
+
output
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Mspec
|
2
2
|
class SpecResult
|
3
|
-
def initialize(error)
|
3
|
+
def initialize(expectation, matcher, error)
|
4
|
+
@test_code = expectation
|
5
|
+
@expected_result = matcher
|
4
6
|
@error = error
|
5
7
|
end
|
6
8
|
|
@@ -8,8 +10,25 @@ module Mspec
|
|
8
10
|
!@error
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
[
|
13
|
+
def failure_message
|
14
|
+
[
|
15
|
+
"Expected: #{@expected_result.value.inspect}",
|
16
|
+
"Got: #{test_code_result.inspect}",
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def trace
|
21
|
+
"#{@error.backtrace[1]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def test_code_result
|
27
|
+
if @test_code.value.is_a?(Proc)
|
28
|
+
@expected_result.test_code_output_string
|
29
|
+
else
|
30
|
+
@test_code.value
|
31
|
+
end
|
13
32
|
end
|
14
33
|
end
|
15
34
|
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.1.
|
4
|
+
version: 0.1.6
|
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-06-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/m-spec/core/expect.rb
|
61
61
|
- lib/m-spec/core/helpers/readable.rb
|
62
62
|
- lib/m-spec/core/matchers/equal.rb
|
63
|
+
- lib/m-spec/core/matchers/output.rb
|
63
64
|
- lib/m-spec/core/spec_error.rb
|
64
65
|
- lib/m-spec/core/spec_result.rb
|
65
66
|
- lib/m-spec/mocks/allow.rb
|