speq 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 32ff60fc943c04afc5c85f9b49c020a08f0e38720eed9f02c7be16aa9e4c1777
4
+ data.tar.gz: b5622c58ca6fd050185092fc4a6fda473393ebdf6d33dc1a8cd1a176c2cbcce6
5
+ SHA512:
6
+ metadata.gz: e088259968e6271760e885a1aef4e90b23b93073633c9828d8e2c241735ae79d4be980f0055b21aabfbf4883f79aec37632ac8e27987b5cf6c099f6aeda6ec2a
7
+ data.tar.gz: 316856e55388a2baf6b919da7c017a7bf3fcdabbac396a3adeabad8842ae675d57a53a5ee1c03a932d38f6e4c97955bd6c1b23b9c5c9f43742c50b53bdae576c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.6
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 speq.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ speq (0.2.0)
5
+ colorize (~> 0.8.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ colorize (0.8.1)
12
+ method_source (0.9.0)
13
+ pry (0.11.3)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ rake (10.5.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 1.16)
23
+ pry (~> 0.11.3)
24
+ rake (~> 10.0)
25
+ speq!
26
+
27
+ BUNDLED WITH
28
+ 1.16.6
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Speq
2
+
3
+ ## A tiny library to build specs with fewer words
4
+
5
+ Speq is TDD library for rapid prototyping in Ruby. It aims to work well anytime testing is desired but writing specs with existing tools may feel excessive.
6
+
7
+ Speq favors simplicity and minimalism, which may not always be compatible with rigorous testing. The existing TDD tools for Ruby are exceptional, and Speq is not a replacement.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'speq'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install speq
24
+
25
+ ## Syntax
26
+
27
+ Speq excels at running many similar tests and checks. It omits explicit descriptions and outputs simple reports.
28
+
29
+ ```ruby
30
+ does :prime? do
31
+ given 0, 1, 8, match: false
32
+ given 2, 3, 97, match: true
33
+ end
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Wherever you want
39
+
40
+ ```ruby
41
+ require 'speq'
42
+
43
+ class Array
44
+ def my_map
45
+ Array.new(length) { |index| yield(self[index])}
46
+ end
47
+ end
48
+
49
+ # Speq.test...
50
+ ```
51
+
52
+ ### With dedicated spec files
53
+
54
+ Speq also offers a simple CLI that lets you run tests written in dedicated spec files.
55
+
56
+ Executing the following command:
57
+
58
+ $ bundle exec speq
59
+
60
+ will recursively search the working directory and run all files that end with `_speq.rb`.
61
+
62
+ To run individual files, specify a list of speq file prefixes. For example, to run tests that are within the files `example_speq.rb` and `sample_speq.rb`, simply execute:
63
+
64
+ $ bundle exec speq example sample
65
+
66
+ Speq files are not expected to require `speq`, but they should require other files that may be needed to run the speqs.
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on [Speq's GitHub](https://github.com/znrm/speq).
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pry'
5
+
6
+ require 'speq'
7
+ include Speq
8
+
9
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/exe/speq ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'speq/cli'
4
+ Speq::CLI.new(ARGV).run
data/lib/speq/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'find'
2
+ require 'colorize'
3
+ require 'speq/test'
4
+
5
+ # Provides a CLI for running Speq
6
+ module Speq
7
+ class CLI
8
+ attr_accessor :tests
9
+
10
+ def initialize(cli_args)
11
+ @files = find_files(cli_args)
12
+ @tests = []
13
+ end
14
+
15
+ def find_files(file_prefixes)
16
+ file_prefixes << '*' if file_prefixes.empty?
17
+
18
+ Dir.glob("#{Dir.pwd}/**/{#{file_prefixes.join(',')}}_speq.rb")
19
+ end
20
+
21
+ def does(subject, &block)
22
+ tests << Test.new(subject, self, &block)
23
+ end
24
+
25
+ def run
26
+ @files.each { |file| instance_eval(File.read(file), file) }
27
+ @tests.each(&:report)
28
+ @tests.all?(&:passed?)
29
+ end
30
+ end
31
+ end
data/lib/speq/fake.rb ADDED
@@ -0,0 +1,5 @@
1
+ # The Fake class inludes a variety of doubles, mocks, stubs, etc.
2
+ module Speq
3
+ class Fake
4
+ end
5
+ end
data/lib/speq/match.rb ADDED
@@ -0,0 +1,26 @@
1
+ # The Match class includes a variety of matchers
2
+ module Speq
3
+ class Match
4
+ attr_reader :actual, :expected, :passed, :args
5
+
6
+ def initialize(actual, match_sym, args, expected = nil)
7
+ @actual = actual
8
+ @expected = expected
9
+ @passed = false
10
+ @args = args
11
+
12
+ evaluate_match(match_sym)
13
+ end
14
+
15
+ def evaluate_match(match_sym)
16
+ case match_sym
17
+ when :eql?, :equal?
18
+ @passed = actual.send(match_sym, expected)
19
+ end
20
+ end
21
+
22
+ def passed?
23
+ @passed
24
+ end
25
+ end
26
+ end
data/lib/speq/test.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'speq/match'
2
+
3
+ # The Test class is a simple implementation of unit test block
4
+ module Speq
5
+ class Test
6
+ attr_reader :method, :reciever, :report
7
+
8
+ def initialize(method_symbol, class_name = Object, &block)
9
+ @method = method_symbol
10
+ @reciever = class_name
11
+ @units = []
12
+
13
+ instance_eval(&block)
14
+ print_report
15
+ end
16
+
17
+ def given(*args, match:)
18
+ args.each do |arg|
19
+ return_value = reciever.send(method, *arg)
20
+
21
+ @units << Match.new(return_value, :eql?, arg, match)
22
+ end
23
+ end
24
+
25
+ def on(*receivers, match:)
26
+ receivers.each do |receiver|
27
+ return_value = receiver.send(method)
28
+
29
+ @units << Match.new(return_value, :eql?, arg, match)
30
+ end
31
+ end
32
+
33
+ def passed?
34
+ @units.all?(&:passed?)
35
+ end
36
+
37
+ def print_report
38
+ report_string = "Testing: #{method}\n"
39
+
40
+ @units.each do |one_test|
41
+ if one_test.passed?
42
+ outcome_text = 'PASSED'
43
+ color = :green
44
+ else
45
+ outcome_text = 'FAILED'
46
+ color = :red
47
+ end
48
+
49
+ indent = ' ' * @method.to_s.length
50
+
51
+ report_string <<
52
+ ["\n#{outcome_text} when given: #{one_test.args}\n".colorize(color),
53
+ " returned: #{one_test.actual}\n".colorize(color),
54
+ " expected: #{one_test.expected}\n".colorize(color)].join
55
+ end
56
+ puts report_string
57
+
58
+ passed?
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Speq
2
+ VERSION = '0.2.0'.freeze
3
+ end
data/lib/speq.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'speq/version'
2
+ require 'speq/test'
3
+ require 'speq/match'
4
+ require 'speq/fake'
5
+ require 'speq/cli'
6
+
7
+ module Speq
8
+ module_function
9
+
10
+ def does(subject, &block)
11
+ Test.new(subject, self, &block).report
12
+ end
13
+ end
data/speq.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'speq/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'speq'
7
+ spec.version = Speq::VERSION
8
+ spec.authors = ['zaniar moradian']
9
+ spec.email = ['moradianzaniar@gmail.com']
10
+
11
+ spec.summary = 'A tiny library to build specs with fewer words.'
12
+ spec.homepage = 'https://github.com/znrm/speq'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+
19
+ spec.bindir = 'exe'
20
+ spec.executables = ['speq']
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry', '~> 0.11.3'
26
+
27
+ spec.add_dependency 'colorize', '~> 0.8.1'
28
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: speq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - zaniar moradian
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-13 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.11.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.11.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
69
+ description:
70
+ email:
71
+ - moradianzaniar@gmail.com
72
+ executables:
73
+ - speq
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - exe/speq
86
+ - lib/speq.rb
87
+ - lib/speq/cli.rb
88
+ - lib/speq/fake.rb
89
+ - lib/speq/match.rb
90
+ - lib/speq/test.rb
91
+ - lib/speq/version.rb
92
+ - speq.gemspec
93
+ homepage: https://github.com/znrm/speq
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.7.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A tiny library to build specs with fewer words.
117
+ test_files: []