m-spec 0.1.3 → 0.1.8

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: fc075272ba943b898b2c652bbc45a3cd6db679dc8dd3bd2f804599828e685208
4
- data.tar.gz: 77ab99a93514f5a12d79c9f4a56b6c183ee337b82743b97b87befc531e0b7e54
3
+ metadata.gz: 6ce2fb3d3541770936da294b63f3815faea69904333bc06c63403ad76a25dfe7
4
+ data.tar.gz: 3ae0e86750afbb3458fd8f33cdac13c1ae72ac5a6f771de746e5967a963a7bb2
5
5
  SHA512:
6
- metadata.gz: a0b57b0fe22b468c721a425e481e1cc351615bb49cb403977b06a8272bf6638010b3d60652f42065eb6ebb34f03102d9836ba4615f334e7ec1e212e4ce157475
7
- data.tar.gz: d683f6752864c146fc66e8f00922cc026f038fc708b2276c436a7d53b0f1ff556ac21eb65ac44ceb1b847c7782e7785a07f5c564da67266a0f1d3a06f86c26d6
6
+ metadata.gz: fe13e5509c611618d7e215c77e799a44f3bc4939afe92e7d09de5404000e7e1bae2af3839f2760dd0d9c43ecf9fb610a057d84878d373d64c3586b864d926783
7
+ data.tar.gz: 8bed6188d906066b77d945d0e296320febf31488266661ef04994a737a51230db3a5394a0461231047a2c9d7576ca4344a28d728c5d932a8f9ba478c2346b976
@@ -0,0 +1,12 @@
1
+ # _____ ____ ____ __ _ __
2
+ # / ___/ _____ ____ _ / __// __/____ / / (_)____ / /_
3
+ # \__ \ / ___// __ `// /_ / /_ / __ \ / / / // __ \ / __/
4
+ # ___/ // /__ / /_/ // __// __// /_/ // /___ / // / / // /_
5
+ # /____/ \___/ \__,_//_/ /_/ 1 \____//_____//_//_/ /_/ \__/
6
+ #
7
+ # The linter file that doesn't lead junior developers to bad habits.
8
+ # https://github.com/makersacademy/scaffolint
9
+ #
10
+ # Configure Rubocop to use the config file in the Scaffolint GitHub repo
11
+ inherit_from:
12
+ - https://raw.githubusercontent.com/makersacademy/scaffolint/v1.1.0/.rubocop.yml
data/README.md CHANGED
@@ -64,14 +64,25 @@ The Animal
64
64
  fails nicely
65
65
  Expected: ROAAAARRRR!
66
66
  Got: little roar!
67
- /path/to/directory/spec/animal_spec.rb:11:in `block (2 levels) in <top (required)>'
67
+ # /path/to/directory/spec/animal_spec.rb:11:in `block (2 levels) in <top (required)>'
68
68
  stubbing
69
69
  we can mock too!
70
70
  ```
71
71
 
72
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.
73
73
 
74
- Remember - you'll have to manage test setup and teardown yourself and keeping your test code dry yourself. Make sure each test runs in isolation.
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.
75
+
76
+ ## Rubocop
77
+
78
+ M-spec comes with rubocop by default, using this [set of rules](https://github.com/makersacademy/scaffolint). To configure your test suite to disable rubocop or to only run rubcop, add an optional configuration file named `.m-spec` to your project root where you run your specs from. You don't need the configuration file - by default your specs will run first, followed by rubocop.
79
+
80
+ You can add either of two options
81
+ - `--no-rubocop` which will ignore running rubocop
82
+ - `--only-rubocop` which will ignore running your tests
83
+
84
+ See [rubocop documentation](https://docs.rubocop.org/rubocop/index.html) for more info - you might be interested in reading about rubocop's autocorrect command.
85
+
75
86
 
76
87
  ## Extending
77
88
 
@@ -88,7 +99,7 @@ m-spec [spec-file]
88
99
  ```
89
100
 
90
101
  ## Pushing to Rubygems
91
- Sign up for an account, check for the gem name you want, and then follow the hints and errors when you
102
+ 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
103
  ```sh
93
104
  $ bundle exec rake release
94
105
  ```
data/exe/m-spec CHANGED
@@ -1,5 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'm-spec'
3
3
 
4
- spec_file = ARGV[0]
5
- require spec_file
4
+ def run_rubocop!
5
+ config = "$GEM_HOME/gems/m-spec-#{Mspec::VERSION}/.rubocop.yml"
6
+ system("bundle exec rubocop --config #{config}")
7
+ end
8
+
9
+ def run_specs!
10
+ spec_file = ARGV[0]
11
+ require spec_file
12
+ end
13
+
14
+ if File.exists?('./.m-spec')
15
+ File.open('./.m-spec', 'r') do |file|
16
+ options = file.read.split
17
+ if options.include?('--only-rubocop')
18
+ run_rubocop!
19
+ elsif options.include?('--no-rubocop')
20
+ run_specs!
21
+ else
22
+ run_specs!
23
+ run_rubocop!
24
+ end
25
+ end
26
+ else
27
+ run_specs!
28
+ run_rubocop!
29
+ end
@@ -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"
@@ -1,6 +1,7 @@
1
1
  COLOUR_CODES = {
2
- true => 32,
3
- false => 31
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
- colour_code = COLOUR_CODES[spec_result.success?]
14
- puts " \e[#{colour_code}m#{str}\e[0m"
15
- unless spec_result.success?
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"
16
18
  spec_result.failure_message.each do |line|
17
- puts " \e[#{colour_code}m#{line}\e[0m"
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.nil?
27
+ Mspec::Expect.new(obj)
28
+ else
29
+ Mspec::Expect.new(block)
30
+ end
31
+ end
22
32
 
23
- def expect(obj)
24
- Mspec::Expect.new(obj)
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,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,10 +12,23 @@ module Mspec
12
12
 
13
13
  def failure_message
14
14
  [
15
- " Expected: #{@expectation.value}",
16
- " Got: #{@matcher.value}",
17
- " #{@error.backtrace[1]}"
15
+ "Expected: #{@expected_result.value.inspect}",
16
+ "Got: #{test_code_result.inspect}",
18
17
  ]
19
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
32
+ end
20
33
  end
21
34
  end
@@ -1,3 +1,3 @@
1
1
  module Mspec
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
+ spec.add_dependency "rubocop", "~> 0.79.0"
26
+
25
27
  spec.add_development_dependency "bundler", "~> 2.1"
26
28
  spec.add_development_dependency "rake", ">= 12.3.3"
27
29
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.8
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-25 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.79.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.79.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,6 +62,7 @@ extensions: []
48
62
  extra_rdoc_files: []
49
63
  files:
50
64
  - ".gitignore"
65
+ - ".rubocop.yml"
51
66
  - CODE_OF_CONDUCT.md
52
67
  - Gemfile
53
68
  - LICENSE.txt
@@ -60,6 +75,7 @@ files:
60
75
  - lib/m-spec/core/expect.rb
61
76
  - lib/m-spec/core/helpers/readable.rb
62
77
  - lib/m-spec/core/matchers/equal.rb
78
+ - lib/m-spec/core/matchers/output.rb
63
79
  - lib/m-spec/core/spec_error.rb
64
80
  - lib/m-spec/core/spec_result.rb
65
81
  - lib/m-spec/mocks/allow.rb