testrocket 0.0.2 → 1.0.0

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
- SHA1:
3
- metadata.gz: e62650b45a99c697c146ea300cb0c6f03a53b9b8
4
- data.tar.gz: 2aecec4e6db2fc1f5a36b488f4212b2dbc420cd1
2
+ SHA256:
3
+ metadata.gz: bc8e7c8a771afae93f8ada5b324550864bc2bd1f8412a54a7098f440abee3791
4
+ data.tar.gz: 77dc8625ffc92a8c67fa23416be68b76d8a64516306d4f6e720d9da49f1941c2
5
5
  SHA512:
6
- metadata.gz: a8161afc11c7646e6144196bf51a512b1aab39da67a80225146dfb9c995c1a488ee022c8b69248996117b8c11988e097117f58402e9b1941cd3a766578151a89
7
- data.tar.gz: 56b62f8767679d0bf04f6e73fad121e1be6a3baeb81d208933df9087526e10a342078455c8b86467420a6043b8aa3e9cd3bd09f2d3b919118f42d8e82fcf3b3b
6
+ metadata.gz: aeb2b9ca986a41655129ad22ff7bd8368da5ddf52bbb0cf92ebd60398910e8cf3257b2ac77f6384e11052a53fe50787b687f4813ec788b952239abfb9da0fc53
7
+ data.tar.gz: 46400342d55f2bcee7d6be7d5ead3c540607cc372ea7608290e82fa624aaa957a329136b860aa16a9a867f47602e2a958c04ae4239610b252fce7d7632b4b479
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .vscode
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in testrocket.gemspec
4
4
  gemspec
data/HISTORY CHANGED
@@ -1,7 +1,21 @@
1
- 0.0.1 - August 10, 2011
1
+ 1.0.0 - October 2, 2019
2
2
 
3
- - Initial release
3
+ - Breaking change: TestRocker now uses refinements to stop it polluting Object.
4
+
5
+ 0.1.0 - February 2, 2015
6
+
7
+ - Switched default output to STDERR instead of STDOUT
8
+ - Moved the methods that do the work into a TestRocket::Live module so...
9
+ - .. a module called TestRocket::Dummy has been added so TestRocket isn't used in production situations
10
+ - Extra tests for showing the location of a failing, passing, or pending test
11
+ - Reversed HISTORY order
12
+ - Merged VERSION constant into main module file
13
+ - Removed the Jenkins CI stuff as I can't remember anything about it
4
14
 
5
15
  0.0.2 - May 31, 2014
6
16
 
7
17
  - Finally pushed extra syntax version to rubygems.org ;-)
18
+
19
+ 0.0.1 - August 10, 2011
20
+
21
+ - Initial release
data/LICENSE CHANGED
@@ -1,9 +1,9 @@
1
1
  This is a modified MIT license.
2
2
 
3
- Copyright © 2011-2012 Peter Cooper (http://peterc.org/)
3
+ Copyright © 2011-2019 Peter Cooper (http://peterc.org/)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
7
7
  The above copyright notice, and every other copyright notice found in this software, and all the attributions in every file, and this permission notice shall be included in all copies or substantial portions of the Software.
8
8
 
9
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  | |_| __|__ \ |_| | | (_) | (__| <| __/ |_
5
5
  \__|\___|___/\__|_| \___/ \___|_|\_\\___|\__|
6
6
 
7
- Testrocket is a super simple (as simple as it gets really) testing library for Ruby 1.9 and higher.
7
+ Testrocket is a super simple (as simple as it gets really) testing library for Ruby 2.0 and higher.
8
8
 
9
9
  It was initially developed for [a CodeBrawl contest](http://codebrawl.com/articles/contest-rundown-ruby-testing-libraries) and it won! People asked me to release it 'for real' so here we are.
10
10
 
@@ -12,12 +12,16 @@ To install:
12
12
 
13
13
  gem install testrocket
14
14
 
15
+ .. or add it to your `Gemfile` in the usual way.
16
+
15
17
  As yet there are no useful bits and pieces for creating test files (look at the example, it's easy!) or Rake tasks. But it's all crazy simple. A few things may be added later on.
16
18
 
19
+ *Note: Prior to version 1, TestRocket extended built-in classes to work, but has (in 2019) been modernized to use refinements to avoid it clashing with third party libraries in real world scenarios (yes, people use this library in real world code!)*
20
+
17
21
  Dependencies
18
22
  ------------
19
23
 
20
- - Ruby 1.9 or higher
24
+ - Ruby 2.1 or higher
21
25
  - minitest/spec (part of MRI 1.9+ standard library)
22
26
 
23
27
  Example
@@ -25,6 +29,7 @@ Example
25
29
 
26
30
  ```ruby
27
31
  require 'testrocket'
32
+ using TestRocket
28
33
 
29
34
  # BASIC USAGE
30
35
  # +-> { block that should succeed }
@@ -45,10 +50,36 @@ require 'testrocket'
45
50
  !-> { "use this for descriptive output and to separate your test parts" }
46
51
  ```
47
52
 
53
+ As well as running tests in separate test files in the 'traditional' way, TestRocket can also be used 'inline' with real world code. A trivial example:
54
+
55
+ ```ruby
56
+ class YourClass
57
+ using TestRocket
58
+
59
+ def initialize
60
+ end
61
+
62
+ def does_something
63
+ # ...
64
+ end
65
+
66
+ +->{ # a test for does_something goes here }
67
+
68
+ def does_something_else
69
+ # ...
70
+ end
71
+
72
+ +->{ # a test for does_something_else goes here }
73
+ -->{ # a test for does_something_else goes here }
74
+ end
75
+ ```
76
+
77
+ In this way, your class is tested each time you run the app in development or test modes. Note that if TestRocket detects `RACK_ENV` is `production`, `RAILS_ENV` is production or Rails is running and `Rails.env.production?` is true, the usual TestRocket methods will simply pass straight through so as to not impede performance on the loading of your app.
78
+
48
79
  Other Features
49
80
  --------------
50
81
 
51
- By default, output is written to STDOUT (as well as returned by the test expressions themselves). You can override where test output goes like so:
82
+ By default, output is written to STDERR (as well as returned by the test expressions themselves). You can override where test output goes like so:
52
83
 
53
84
  ```ruby
54
85
  TestRocket.out = File.new('/dev/null', 'w')
@@ -56,9 +87,13 @@ TestRocket.out = File.new('/dev/null', 'w')
56
87
 
57
88
  TestRocket.out also supports Logger instances.
58
89
 
59
- Authors
90
+ Credits
60
91
  -------
61
92
 
62
93
  Initial concept and maintenance by Peter Cooper
63
94
 
64
95
  Extra concepts and code by Christoph Grabo
96
+
97
+ Thanks to Gary Bernhardt for often praising and shining attention on TestRocket :-)
98
+
99
+ Thanks to Serge Bedzhyk for modernizing the library to use refinements.
@@ -1,18 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # TestRocket Module to refine lambdas an use them for lightweight tests
5
+ #
1
6
  module TestRocket
2
- extend Module.new { attr_accessor :out }
7
+ VERSION = '1.0.0'
3
8
 
4
- def _test(a, b); send((call rescue()) ? a : b) end
9
+ extend Module.new { attr_accessor :out }
5
10
 
6
- def +@; _show _test :_pass, :_fail end
7
- def -@; _show _test :_fail, :_pass end
8
- def ~; _show _pend; end
9
- def !; _show _desc; end
11
+ refine Proc do
12
+ # Include TestRocket methods WITHOUT implementation selected
13
+ Proc.send :include, TestRocket
10
14
 
11
- def _show(r); (TestRocket.out || $>) << r + "\n"; r end
12
- def _pass; " OK" end
13
- def _fail; " FAIL @ #{source_location * ':'}" end
14
- def _pend; "PENDING '#{call}' @ #{source_location * ':'}" end
15
- def _desc; " FIRE '#{call}'!" end
16
- end
15
+ # If we're in a production environment, the tests shall do nothing.
16
+ if ENV['RACK_ENV'] == 'production' ||
17
+ (defined?(Rails) && Rails.env.production?) ||
18
+ ENV['RAILS_ENV'] == 'production'
19
+ def _test(a, b); end
20
+ def _show(r); end
21
+ def _pend; end
22
+ def _desc; end
23
+ else
24
+ def _test(a, b); send((call rescue()) ? a : b) end
25
+ def _show(r); (TestRocket.out || STDERR) << r + "\n"; r end
26
+ def _pass; ' OK' end
27
+ def _fail; " FAIL @ #{source_location * ':'}" end
28
+ def _pend; "PENDING '#{call}' @ #{source_location * ':'}" end
29
+ def _desc; " FIRE '#{call}'!" end
30
+ end
17
31
 
18
- Proc.send :include, TestRocket
32
+ def +@; _show _test :_pass, :_fail end
33
+ def -@; _show _test :_fail, :_pass end
34
+ def ~; _show _pend end
35
+ def !; _show _desc end
36
+ end
37
+ end
@@ -1,33 +1,66 @@
1
1
  require_relative 'helper'
2
2
 
3
- describe TestRocket do
4
- it "should find emptiness non-truthful by default" do
5
- (+->{}).must_match(/FAIL/)
6
- end
7
-
8
- it "should pass a simple positive assertion" do
9
- (+->{ 2 + 2 == 4 }).must_match(/OK/)
10
- end
3
+ class RefinementTest
4
+ using TestRocket
11
5
 
12
- it "should pass a simple negative assertion" do
13
- (-->{ 2 + 2 == 5 }).must_match(/OK/)
14
- end
15
-
16
- it "should fail a simple erroneous assertion" do
17
- (+->{ 2 + 2 == 5 }).must_match(/FAIL/)
18
- end
6
+ def self.test!
7
+ describe TestRocket do
8
+ it 'should find emptiness non-truthful by default' do
9
+ (+->{}).must_match(/FAIL/)
10
+ (+->{}).must_match("#{__FILE__}:#{__LINE__}")
11
+ end
19
12
 
20
- it "should fail a simple correct assertion assumed to fail" do
21
- (-->{ 2 + 2 == 4 }).must_match(/FAIL/)
22
- end
23
-
24
- it "should give a pending notice" do
25
- (~->{ "a pending test" }).must_match(/PENDING/)
26
- (~->{ "a pending test" }).must_match(/a pending test/)
13
+ it 'should pass a simple positive assertion' do
14
+ (+->{ 2 + 2 == 4 }).must_match(/OK/)
15
+ end
16
+
17
+ it 'should pass a simple negative assertion' do
18
+ (-->{ 2 + 2 == 5 }).must_match(/OK/)
19
+ end
20
+
21
+ it 'should fail a simple erroneous assertion' do
22
+ (+->{ 2 + 2 == 5 }).must_match(/FAIL/)
23
+ (+->{ 2 + 2 == 5 }).must_match("#{__FILE__}:#{__LINE__}")
24
+ end
25
+
26
+ it 'should fail a simple correct assertion assumed to fail' do
27
+ (-->{ 2 + 2 == 4 }).must_match(/FAIL/)
28
+ (-->{ 2 + 2 == 4 }).must_match("#{__FILE__}:#{__LINE__}")
29
+ end
30
+
31
+ it 'should give a pending notice' do
32
+ (~->{ 'a pending test' }).must_match(/PENDING/)
33
+ (~->{ 'a pending test' }).must_match(/a pending test/)
34
+ (~->{ 'a pending test' }).must_match("#{__FILE__}:#{__LINE__}")
35
+ end
36
+
37
+ it 'should fire a description rocket' do
38
+ (!->{ 'a description' }).must_match(/FIRE/)
39
+ (!->{ 'a description' }).must_match(/a description/)
40
+ end
41
+
42
+ it 'would influence Ruby Proc if TestRocket used explitly' do
43
+ (
44
+ ok = ->() { nil }
45
+ !ok
46
+ ).must_match(/FIRE/)
47
+ end
48
+ end
27
49
  end
28
-
29
- it "should fire a description rocket" do
30
- (!->{ "a description" }).must_match(/FIRE/)
31
- (!->{ "a description" }).must_match(/a description/)
50
+ end
51
+
52
+ class NoRefinementTest
53
+ def self.test!
54
+ describe 'Without `using TestRocket`' do
55
+ it 'should not influence global Ruby scope and other libs' do
56
+ (
57
+ ok = ->() { nil }
58
+ !ok
59
+ ).must_equal(false)
60
+ end
61
+ end
32
62
  end
33
63
  end
64
+
65
+ RefinementTest.test!
66
+ NoRefinementTest.test!
@@ -1,21 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "testrocket/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'testrocket'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "testrocket"
7
- s.version = Testrocket::VERSION
6
+ s.name = 'testrocket'
7
+ s.version = TestRocket::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Peter Cooper","Christoph Grabo"]
10
- s.email = ["git@peterc.org","chris@dinarrr.com"]
11
- s.homepage = "http://github.com/peterc/testrocket"
9
+ s.authors = ['Peter Cooper', 'Christoph Grabo']
10
+ s.email = %w[git@peterc.org chris@dinarrr.com]
11
+ s.homepage = 'http://github.com/peterc/testrocket'
12
12
  s.summary = %q{A super lightweight lamdba-based testing library for Ruby}
13
13
  s.description = %q{A super lightweight lamdba-based testing library for Ruby}
14
14
 
15
- s.rubyforge_project = "testrocket"
15
+ s.rubyforge_project = 'testrocket'
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testrocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Cooper
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-31 00:00:00.000000000 Z
12
+ date: 2019-10-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A super lightweight lamdba-based testing library for Ruby
15
15
  email:
@@ -20,15 +20,12 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - ".gitignore"
23
- - ".travis.yml"
24
23
  - Gemfile
25
- - Gemfile.travis
26
24
  - HISTORY
27
25
  - LICENSE
28
26
  - README.md
29
27
  - Rakefile
30
28
  - lib/testrocket.rb
31
- - lib/testrocket/version.rb
32
29
  - test/helper.rb
33
30
  - test/test_testrocket.rb
34
31
  - testrocket.gemspec
@@ -51,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
48
  version: '0'
52
49
  requirements: []
53
50
  rubyforge_project: testrocket
54
- rubygems_version: 2.2.0
51
+ rubygems_version: 2.7.8
55
52
  signing_key:
56
53
  specification_version: 4
57
54
  summary: A super lightweight lamdba-based testing library for Ruby
@@ -1,7 +0,0 @@
1
- rvm:
2
- - 1.9.2
3
- gemfile: gemfiles/Gemfile.travis
4
- notifications:
5
- recipients:
6
- - chris@dinarrr.com
7
-
@@ -1,6 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rake" # added for travis-ci.org
4
-
5
- # Specify your gem's dependencies in testrocket.gemspec
6
- gemspec
@@ -1,3 +0,0 @@
1
- module Testrocket
2
- VERSION = "0.0.2"
3
- end