m-spec 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe47e5d229c865a8619c6f62bc61d85535df6455cdc3f6c6c3f4c23071b633bd
4
- data.tar.gz: 4a9085d8178b12ef11170b053f8e17d27a8e8a0666219541a3937f616af133f6
3
+ metadata.gz: 6420629e2b27b246efaca92e6ad572603eaaf05bfaf716b0d386cadebafab8f9
4
+ data.tar.gz: 33e8d052ef1d6513a06e9048ac12ce95c51b1597c3ef7246b4d360619b304cab
5
5
  SHA512:
6
- metadata.gz: 0a9982cf39b798aadc96fb67629bfc77935e4e417b22843a9bf411a5cc5431a64378e98ac3610eb6e34ebe2c92f1bc8072324baae2cbb7c77c2df2a6169045f0
7
- data.tar.gz: c20edd5f8e4f083bdc675d16ed844069c15386a4e78056c2c7017c6c9930a2bd4961d7df130ecd13368a798a81a8a7fc3b80e4c445e2c27c00f3c6e9c43f1560
6
+ metadata.gz: f9484c58fa989d6dea4c2a94abed38d2d769b04c663c3206588961d41858f3ae1c2afda4cfac94b515c9364191131b96913d335d1379765f8af495ec6da9ddba
7
+ data.tar.gz: 21ba3b262a018015878cac2b140acbde0e46ad6e916cb17de44e1a25ea4861d49478d67cd05050d354c96ac180647110b3a9937e452c86319cc3098c5ab24255
@@ -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"
@@ -22,8 +22,16 @@ def it(str)
22
22
  end
23
23
  end
24
24
 
25
- def expect(obj)
26
- Mspec::Expect.new(obj)
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
32
+
33
+ def output(string)
34
+ Mspec::Matchers::Output.new(string)
27
35
  end
28
36
 
29
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,8 +1,8 @@
1
1
  module Mspec
2
2
  class SpecResult
3
3
  def initialize(expectation, matcher, error)
4
- @expectation = expectation
5
- @matcher = matcher
4
+ @test_code = expectation
5
+ @expected_result = matcher
6
6
  @error = error
7
7
  end
8
8
 
@@ -12,13 +12,23 @@ module Mspec
12
12
 
13
13
  def failure_message
14
14
  [
15
- "Expected: #{@matcher.value}",
16
- "Got: #{@expectation.value}",
15
+ "Expected: #{@expected_result.value.inspect}",
16
+ "Got: #{test_code_result.inspect}",
17
17
  ]
18
18
  end
19
19
 
20
20
  def trace
21
21
  "#{@error.backtrace[1]}"
22
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
32
+ end
23
33
  end
24
34
  end
@@ -1,3 +1,3 @@
1
1
  module Mspec
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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.5
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-26 00:00:00.000000000 Z
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