m-spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 92375890d1da886c3ae53626b708eba8d93d00076dabd9dc9f2282f67d860032
4
+ data.tar.gz: 62918be644fb75c3d5831c2884cfdf6099203c59cc31bce3129a1566d4b2c6f6
5
+ SHA512:
6
+ metadata.gz: 332454bdef60665103d66612748d42b9a6bd1af25c96228ae2b0009c236af8871f1d809100ad20905ef4d217ef65e9ecc9a64be6a35a88aab21579447cf59680
7
+ data.tar.gz: ae2b63dac9719375fa1bc286c43b0b9410ec9cc1e5a08c350301da9aa08e1f8032987315eb62a5f6f2d925cbb8d5a5dfb2133b79b1b0aab89d78930824340725
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dearshrewdwit@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mspec.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Edward Withers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,90 @@
1
+ # Mspec
2
+
3
+ The lightest-weight spec framework in ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mspec'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mspec
20
+
21
+ ## Usage
22
+
23
+ We care about isolating unit tests, so there's a very simple mocking library.
24
+
25
+ ```ruby
26
+ # source code
27
+ class Animal
28
+ def roar
29
+ "ROAAAARRRR!"
30
+ end
31
+ end
32
+
33
+ # test code
34
+ describe 'The Animal' do
35
+ it 'can roar' do
36
+ animal = Animal.new
37
+ expect(animal.roar).to eq "ROAAAARRRR!"
38
+ end
39
+
40
+ it 'gives a lovely red when it fails' do
41
+ animal = Animal.new
42
+ expect(animal.roar).to eq "little roar!"
43
+ end
44
+ end
45
+
46
+ describe 'stubbing' do
47
+ it 'we can mock too!' do
48
+ mock = test_double
49
+ allow(mock).to receive(:speak) { 'Hello!' }
50
+ expect(mock.speak).to eq 'Hello!'
51
+ end
52
+ end
53
+ ```
54
+
55
+ To run your specs, pass the spec file directly as an argument. You have to run individual spec files.
56
+
57
+ ```sh
58
+ $ mspec ./spec/animal_spec.rb
59
+ ```
60
+
61
+ ```
62
+ The Animal
63
+ returns a string
64
+ fails nicely
65
+ /path/to/directory/app/spec/animal_spec.rb:11:in block (2 levels) in <top (required)>'
66
+ stubbing
67
+ we can mock too!
68
+ ```
69
+
70
+ It's got simple one-level indentation and simple colour coding for test passes and failures. Failures will give you only the spec file path and line number.
71
+
72
+ Remember - you'll have to manage test setup and test cleanup yourself, while keeping your test code dry also yourself. Make sure each test runs in isolation.
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dearshrewdwit/mspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the Mspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dearshrewdwit/mspec/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mspec"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'm-spec'
3
+
4
+ spec_file = ARGV[0]
5
+ require spec_file
@@ -0,0 +1,12 @@
1
+ require "m-spec/version"
2
+
3
+ require "m-spec/core/expect"
4
+ require "m-spec/core/spec_error"
5
+ require "m-spec/core/spec_result"
6
+ require "m-spec/core/matchers/equal"
7
+ require "m-spec/core/helpers/readable"
8
+
9
+ require "m-spec/mocks/allow"
10
+ require "m-spec/mocks/mock"
11
+ require "m-spec/mocks/stub"
12
+ require "m-spec/mocks/helpers/readable"
@@ -0,0 +1,17 @@
1
+ module Mspec
2
+ class Expect
3
+ def initialize(value)
4
+ @value = value
5
+ end
6
+
7
+ def to(matcher)
8
+ begin
9
+ raise SpecError.new unless matcher.check(@value)
10
+ rescue SpecError => e
11
+ data = e
12
+ end
13
+
14
+ SpecResult.new(data)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ COLOUR_CODES = {
2
+ true => 32,
3
+ false => 31
4
+ }
5
+
6
+ def describe(str)
7
+ puts str
8
+ yield
9
+ end
10
+
11
+ def it(str)
12
+ 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?
16
+ spec_result.simple_stack_trace.each do |stackline|
17
+ puts " \e[#{colour_code}m#{stackline}\e[0m"
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+ def expect(obj)
24
+ Mspec::Expect.new(obj)
25
+ end
26
+
27
+ def eq(obj)
28
+ Mspec::Matchers::Equal.new(obj)
29
+ end
@@ -0,0 +1,13 @@
1
+ module Mspec
2
+ module Matchers
3
+ class Equal
4
+ def initialize(value)
5
+ @value = value
6
+ end
7
+
8
+ def check(value)
9
+ @value == value
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Mspec
2
+ class SpecError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,15 @@
1
+ module Mspec
2
+ class SpecResult
3
+ def initialize(error)
4
+ @error = error
5
+ end
6
+
7
+ def success?
8
+ !@error
9
+ end
10
+
11
+ def simple_stack_trace
12
+ [@error.backtrace[1]]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Mspec
2
+ module Mocks
3
+ class Allow
4
+ def initialize(obj)
5
+ @obj = obj
6
+ end
7
+
8
+ def to(stub)
9
+ @obj.define_singleton_method(stub.name) { stub.return_value }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ def test_double(name = 'anonymous')
2
+ Mspec::Mocks::Mock.new(name)
3
+ end
4
+
5
+ def allow(obj)
6
+ Mspec::Mocks::Allow.new(obj)
7
+ end
8
+
9
+ def receive(method, &block)
10
+ Mspec::Mocks::Stub.new(method, block.call)
11
+ end
@@ -0,0 +1,9 @@
1
+ module Mspec
2
+ module Mocks
3
+ class Mock
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module Mspec
2
+ module Mocks
3
+ class Stub
4
+ attr_reader :name, :return_value
5
+
6
+ def initialize(name, return_value)
7
+ @name = name
8
+ @return_value = return_value
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Mspec
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "m-spec/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "m-spec"
7
+ spec.version = Mspec::VERSION
8
+ spec.authors = ["Edward Withers"]
9
+ spec.email = ["dearshrewdwit@gmail.com"]
10
+
11
+ spec.summary = %q{The lightest-weight testing framework in Ruby}
12
+ spec.description = %q{A testing framework designed both for beginners to reduce the complexity and for experts who want a barebones framework.}
13
+ spec.homepage = "https://github.com/dearshrewdwit/m-spec"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 2.1"
26
+ spec.add_development_dependency "rake", ">= 12.3.3"
27
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: m-spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Edward Withers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ description: A testing framework designed both for beginners to reduce the complexity
42
+ and for experts who want a barebones framework.
43
+ email:
44
+ - dearshrewdwit@gmail.com
45
+ executables:
46
+ - m-spec
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - exe/m-spec
59
+ - lib/m-spec.rb
60
+ - lib/m-spec/core/expect.rb
61
+ - lib/m-spec/core/helpers/readable.rb
62
+ - lib/m-spec/core/matchers/equal.rb
63
+ - lib/m-spec/core/spec_error.rb
64
+ - lib/m-spec/core/spec_result.rb
65
+ - lib/m-spec/mocks/allow.rb
66
+ - lib/m-spec/mocks/helpers/readable.rb
67
+ - lib/m-spec/mocks/mock.rb
68
+ - lib/m-spec/mocks/stub.rb
69
+ - lib/m-spec/version.rb
70
+ - m-spec.gemspec
71
+ homepage: https://github.com/dearshrewdwit/m-spec
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.1.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: The lightest-weight testing framework in Ruby
94
+ test_files: []