polizia 1.0.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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gs/bin/cutest +27 -0
  3. data/.gs/cache/clap-1.0.0.gem +0 -0
  4. data/.gs/cache/cutest-1.2.3.gem +0 -0
  5. data/.gs/gems/clap-1.0.0/LICENSE +19 -0
  6. data/.gs/gems/clap-1.0.0/Rakefile +6 -0
  7. data/.gs/gems/clap-1.0.0/clap.gemspec +11 -0
  8. data/.gs/gems/clap-1.0.0/lib/clap.rb +46 -0
  9. data/.gs/gems/clap-1.0.0/test/clap_test.rb +43 -0
  10. data/.gs/gems/cutest-1.2.3/.gitignore +1 -0
  11. data/.gs/gems/cutest-1.2.3/CHANGELOG.md +26 -0
  12. data/.gs/gems/cutest-1.2.3/LICENSE +19 -0
  13. data/.gs/gems/cutest-1.2.3/Makefile +6 -0
  14. data/.gs/gems/cutest-1.2.3/README.markdown +189 -0
  15. data/.gs/gems/cutest-1.2.3/bin/cutest +21 -0
  16. data/.gs/gems/cutest-1.2.3/cutest.gemspec +19 -0
  17. data/.gs/gems/cutest-1.2.3/lib/cutest.rb +187 -0
  18. data/.gs/gems/cutest-1.2.3/test/assert.rb +9 -0
  19. data/.gs/gems/cutest-1.2.3/test/assert_equal.rb +9 -0
  20. data/.gs/gems/cutest-1.2.3/test/assert_raise.rb +45 -0
  21. data/.gs/gems/cutest-1.2.3/test/fixtures/exception.rb +7 -0
  22. data/.gs/gems/cutest-1.2.3/test/fixtures/fail_custom_assertion.rb +7 -0
  23. data/.gs/gems/cutest-1.2.3/test/fixtures/fail_custom_message.rb +3 -0
  24. data/.gs/gems/cutest-1.2.3/test/fixtures/failure.rb +3 -0
  25. data/.gs/gems/cutest-1.2.3/test/fixtures/failure_in_loaded_file.rb +1 -0
  26. data/.gs/gems/cutest-1.2.3/test/fixtures/only_run_given_scope_name.rb +15 -0
  27. data/.gs/gems/cutest-1.2.3/test/fixtures/outside_block.rb +5 -0
  28. data/.gs/gems/cutest-1.2.3/test/fixtures/success.rb +7 -0
  29. data/.gs/gems/cutest-1.2.3/test/prepare.rb +25 -0
  30. data/.gs/gems/cutest-1.2.3/test/run.rb +110 -0
  31. data/.gs/gems/cutest-1.2.3/test/scopes.rb +27 -0
  32. data/.gs/gems/cutest-1.2.3/test/setup.rb +29 -0
  33. data/.gs/specifications/clap-1.0.0.gemspec +31 -0
  34. data/.gs/specifications/cutest-1.2.3.gemspec +34 -0
  35. data/Gemfile +3 -0
  36. data/Gemfile.lock +21 -0
  37. data/Rakefile +20 -0
  38. data/lib/polizia.rb +29 -0
  39. data/polizia.gemspec +14 -0
  40. data/test/all.rb +25 -0
  41. metadata +97 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4e0b10f8f51a439ac2f47f77a52c8be3066412d
4
+ data.tar.gz: 357a49999de91b325bb629e6f7b0af03d8b886da
5
+ SHA512:
6
+ metadata.gz: 8bdf2daede78ba12841191b6b4925a34cad7e688f967969a5350712c7de2a4021949328610fb693d3c332636a574643e3742179dc48d68f941f00e2961ca09e4
7
+ data.tar.gz: df5cd7fc8140b9225f5e2d2a73f4c06692be60a439a639c54fd1f718ea92e31ed2725b9d721355781f4ff5166327796f859cac6342dbe0d4b6872cd0cb3f6a52
data/.gs/bin/cutest ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'cutest' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ version = ">= 0.a"
12
+
13
+ if ARGV.first
14
+ str = ARGV.first
15
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+ if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+ version = $1
18
+ ARGV.shift
19
+ end
20
+ end
21
+
22
+ if Gem.respond_to?(:activate_bin_path)
23
+ load Gem.activate_bin_path('cutest', 'cutest', version)
24
+ else
25
+ gem "cutest", version
26
+ load Gem.bin_path("cutest", "cutest", version)
27
+ end
Binary file
Binary file
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ task :test do
2
+ require "cutest"
3
+ Cutest.run(Dir["test/*.rb"])
4
+ end
5
+
6
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "clap"
3
+ s.version = "1.0.0"
4
+ s.summary = "Command line argument parsing for simple applications."
5
+ s.description = "Clap is a small library that can be bundled with your command line application. It covers the simple case of executing code based on the flags or parameters passed."
6
+ s.authors = ["Michel Martens"]
7
+ s.email = ["michel@soveran.com"]
8
+ s.homepage = "http://github.com/soveran/clap"
9
+ s.files = Dir[ "LICENSE", "README.markdown", "Rakefile", "lib/**/*.rb", "*.gemspec", "test/**/*.rb" ]
10
+ s.add_development_dependency "cutest"
11
+ end
@@ -0,0 +1,46 @@
1
+ class Clap
2
+ attr :argv
3
+ attr :opts
4
+
5
+ def self.run(args, opts)
6
+ new(args, opts).run
7
+ end
8
+
9
+ def initialize(argv, opts)
10
+ @argv = argv.dup
11
+ @opts = opts
12
+ end
13
+
14
+ def run
15
+ args = []
16
+
17
+ while argv.any?
18
+
19
+ item = argv.shift
20
+ flag = opts[item]
21
+
22
+ if flag
23
+
24
+ # Work around lambda semantics in 1.8.7.
25
+ arity = [flag.arity, 0].max
26
+
27
+ # Raise if there are not enough parameters
28
+ # available for the flag.
29
+ if argv.size < arity
30
+ raise ArgumentError
31
+ end
32
+
33
+ # Call the lambda with N items from argv,
34
+ # where N is the lambda's arity.
35
+ flag.call(*argv.shift(arity))
36
+ else
37
+
38
+ # Collect the items that don't correspond to
39
+ # flags.
40
+ args << item
41
+ end
42
+ end
43
+
44
+ args
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path("../lib/clap", File.dirname(__FILE__))
2
+
3
+ test "flag with one argument" do
4
+ result = Clap.run %w(-x y), "-x" => lambda { |flag| assert flag == "y" }
5
+ assert result == []
6
+ end
7
+
8
+ test "flag with more than one argument" do
9
+ result = Clap.run %w(-x y z), "-x" => lambda { |y, z| assert [y, z] == %w(y z) }
10
+ assert result == []
11
+ end
12
+
13
+ test "flag with wrong number of arguments" do
14
+ assert_raise(ArgumentError) do
15
+ Clap.run %w(-x), "-x" => lambda { |flag| }
16
+ end
17
+ end
18
+
19
+ test "extract flags with parameters" do
20
+ result = Clap.run %w(a b -x y c), "-x" => lambda { |flag| assert flag == "y" }
21
+ assert result == %w(a b c)
22
+ end
23
+
24
+ test "extract flags with zero arity" do
25
+ result = Clap.run %w(a b -x c), "-x" => lambda { || }
26
+ assert result == %w(a b c)
27
+ end
28
+
29
+ test "extract flags with no parameters" do
30
+ result = Clap.run %w(a b -x c), "-x" => lambda {}
31
+ assert result == %w(a b c)
32
+ end
33
+
34
+ test "use a method instead of a lambda" do
35
+ class Foo
36
+ def self.bar(flag)
37
+ assert flag == "y"
38
+ end
39
+ end
40
+
41
+ result = Clap.run %w(a b -x y c), "-x" => Foo.method(:bar)
42
+ assert result == %w(a b c)
43
+ end
@@ -0,0 +1 @@
1
+ /pkg
@@ -0,0 +1,26 @@
1
+ 1.2.3 - 2015-12-04
2
+ ==================
3
+
4
+ * `assert_raise` now works with lower-level exceptions.
5
+
6
+ * `assert` can now receive a custom failure message, which should help write
7
+ better custom assertions.
8
+
9
+ * `cutest -v` now exits after printing the version number.
10
+
11
+ 1.2.2 - 2014-11-05
12
+ ==================
13
+
14
+ * `assert_raise` now returns the raised exception.
15
+
16
+ * Use `-s` to run a single scope.
17
+
18
+ 1.2.1 - 2013-08-14
19
+ ==================
20
+
21
+ * `cutest(1)` now exits with a non-zero status when a test fails.
22
+
23
+ Previous versions
24
+ =================
25
+
26
+ Check the commit list for earlier changes.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Damian Janowski & Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ TESTS=$(shell ls test/*.rb)
2
+
3
+ test:
4
+ ruby -W2 bin/cutest $(TESTS)
5
+
6
+ .PHONY: test
@@ -0,0 +1,189 @@
1
+ Cutest
2
+ =======
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/cutest.svg)](https://badge.fury.io/rb/cutest)
5
+
6
+ Forking tests.
7
+
8
+ Description
9
+ -----------
10
+
11
+ Each test file is run in a forked process to avoid shared state. Once a failure
12
+ is found, you get a report detailing what failed and how to locate the error
13
+ and the rest of the file is skipped.
14
+
15
+ You can use the `scope` command around tests: it guarantees that no instance
16
+ variables are shared between tests.
17
+
18
+ There are two commands very similar in nature, but with a subtle difference that
19
+ makes them easy to combine in order to satisfy different needs: `prepare` and
20
+ `setup`.
21
+
22
+ The `prepare` blocks are executed before each test. If you call `prepare` many
23
+ times, each passed block is appended to an array. When the test is run, all
24
+ those prepare blocks are executed in order. The result of the block is
25
+ discarded, so it is only useful for preparing the environment (flushing the
26
+ database, removing a directory, etc.).
27
+
28
+ The `setup` block is executed before each test and the result is passed as a
29
+ parameter to the `test` block. Unlike `prepare`, each definition of `setup`
30
+ overrides the previous one. Even if you can declare instance variables and
31
+ share them between tests, the recommended usage is to pass the result of the
32
+ block as a parameter to the `test` blocks.
33
+
34
+ The `test` method executes the passed block after running `prepare` and
35
+ `setup`. This is where assertions must be declared.
36
+
37
+ Three assertions are available: `assert`, that accepts a value and raises
38
+ if it's false or nil; `assert_equal`, that raises if its arguments are not
39
+ equal; and `assert_raise`, that executes a passed block and compares the raised
40
+ exception to the expected one. In all cases, if the expectation is no met, an
41
+ `AssertionFailed` exception is raised.
42
+
43
+ You can customize the output of `assert` by providing a second argument with
44
+ a string you want to get as an error report if the assertion is not fulfilled.
45
+ This can also be used as a simple building block to build custom assertions.
46
+
47
+ Usage
48
+ -----
49
+
50
+ In your terminal:
51
+
52
+ $ cutest test/*.rb
53
+
54
+ In your tests:
55
+
56
+ ````ruby
57
+ setup do
58
+ {:a => 23, :b => 43}
59
+ end
60
+
61
+ test "should receive the result of the setup block as a parameter" do |params|
62
+ assert params == {:a => 23, :b => 43}
63
+ end
64
+
65
+ test "should evaluate the setup block before each test" do |params|
66
+ params[:a] = nil
67
+ end
68
+
69
+ test "should preserve the original values from the setup" do |params|
70
+ assert 23 == params[:a]
71
+ end
72
+ ```
73
+
74
+ An example working with a prepare block:
75
+ ````ruby
76
+ prepare do
77
+ Ohm.flush
78
+ end
79
+
80
+ setup do
81
+ Ohm.redis.get("foo")
82
+ end
83
+
84
+ test do |foo|
85
+ assert foo.nil?
86
+ end
87
+ ````
88
+
89
+ And working with scopes:
90
+ ````ruby
91
+ setup do
92
+ @foo = true
93
+ end
94
+
95
+ @bar = true
96
+
97
+ scope do
98
+ test "should not share instance variables" do |foo|
99
+ assert !defined?(@foo)
100
+ assert !defined?(@bar)
101
+ assert foo == true
102
+ end
103
+ end
104
+ ````
105
+
106
+ The tests in these two examples will pass.
107
+
108
+ Unlike other testing frameworks, Cutest does not compile all the tests before
109
+ running them.
110
+
111
+ A simple example for adding a custom `empty` assertion:
112
+ ````ruby
113
+ def assert_empty(string)
114
+ assert(string.empty?, "not empty")
115
+ end
116
+
117
+ test "failed custom assertion" do
118
+ assert_empty "foo"
119
+ end
120
+ ````
121
+
122
+ Handling errors
123
+ ---------------
124
+
125
+ If you get an error when running the tests, this is what you will see:
126
+ ````bash
127
+ Exception: assert_equal 24, params[:a] # 24 != 23
128
+ test/setup.rb +14
129
+ ````
130
+ Running the build
131
+ -----------------
132
+
133
+ Using Rake:
134
+ ````ruby
135
+ task :test do
136
+ exec "cutest test/*.rb"
137
+ end
138
+
139
+ task :default => :test
140
+ ````
141
+
142
+ Using Make:
143
+ ````yml
144
+ .PHONY: test
145
+
146
+ test:
147
+ cutest test/*.rb
148
+ ````
149
+ Command-line interface
150
+ ----------------------
151
+
152
+ The tool `cutest` accepts a list of files and sends them to `Cutest.run`. If
153
+ you need to require a file or library before running the tests, as is the case
154
+ with test helpers, use the `-r` flag:
155
+
156
+ $ cutest -r ./test/helper.rb ./test/*_test.rb
157
+
158
+ If you want to check which version you are running, try the `-v` flag.
159
+
160
+ Installation
161
+ ------------
162
+
163
+ $ gem install cutest
164
+
165
+ License
166
+ -------
167
+
168
+ Copyright (c) 2010 Damian Janowski and Michel Martens
169
+
170
+ Permission is hereby granted, free of charge, to any person
171
+ obtaining a copy of this software and associated documentation
172
+ files (the "Software"), to deal in the Software without
173
+ restriction, including without limitation the rights to use,
174
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
175
+ copies of the Software, and to permit persons to whom the
176
+ Software is furnished to do so, subject to the following
177
+ conditions:
178
+
179
+ The above copyright notice and this permission notice shall be
180
+ included in all copies or substantial portions of the Software.
181
+
182
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
183
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
184
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
185
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
186
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
187
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
188
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
189
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.empty?
4
+ puts "usage: cutest [-v] [-r lib] [-o test] [-s scope] file ..."
5
+ exit
6
+ end
7
+
8
+ require_relative "../lib/cutest"
9
+ require "clap"
10
+
11
+ files = Clap.run ARGV,
12
+ "-r" => lambda { |file| require file },
13
+ "-o" => lambda { |name| cutest[:only] = name },
14
+ "-s" => lambda { |name| cutest[:scope] = name },
15
+ "-v" => lambda { puts Cutest::VERSION; exit }
16
+
17
+ if files.any?
18
+ success = Cutest.run(Dir[*files])
19
+
20
+ exit(1) unless success
21
+ end
@@ -0,0 +1,19 @@
1
+ require "./lib/cutest"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "cutest"
5
+ s.version = Cutest::VERSION
6
+ s.summary = "Forking tests."
7
+ s.description = "Run tests in separate processes to avoid shared state."
8
+ s.authors = ["Damian Janowski", "Michel Martens", "Cyril David"]
9
+ s.email = ["djanowski@dimaion.com", "michel@soveran.com", "me@cyrildavid.com"]
10
+ s.homepage = "https://github.com/djanowski/cutest"
11
+
12
+ s.license = "MIT"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+
16
+ s.executables.push "cutest"
17
+
18
+ s.add_dependency "clap"
19
+ end
@@ -0,0 +1,187 @@
1
+ class Cutest
2
+ unless defined?(VERSION)
3
+ VERSION = "1.2.3"
4
+ FILTER = %r[/(ruby|jruby|rbx)[-/]([0-9\.])+]
5
+ CACHE = Hash.new { |h, k| h[k] = File.readlines(k) }
6
+ end
7
+
8
+ def self.run(files)
9
+ status = files.all? do |file|
10
+ run_file(file)
11
+
12
+ Process.wait2.last.success?
13
+ end
14
+
15
+ puts
16
+
17
+ status
18
+ end
19
+
20
+ def self.run_file(file)
21
+ fork do
22
+ begin
23
+ load(file)
24
+
25
+ rescue LoadError, SyntaxError
26
+ display_error
27
+ exit 1
28
+
29
+ rescue StandardError
30
+ trace = $!.backtrace
31
+ pivot = trace.index { |line| line.match(file) }
32
+
33
+ puts "\n test: %s" % cutest[:test]
34
+
35
+ if pivot
36
+ other = trace[0..pivot].select { |line| line !~ FILTER }
37
+ other.reverse.each { |line| display_trace(line) }
38
+ else
39
+ display_trace(trace.first)
40
+ end
41
+
42
+ display_error
43
+
44
+ exit 1
45
+ end
46
+ end
47
+ end
48
+
49
+ def self.code(fn, ln)
50
+ begin
51
+ CACHE[fn][ln.to_i - 1].strip
52
+ rescue
53
+ "(Can't display line)"
54
+ end
55
+ end
56
+
57
+ def self.display_error
58
+ print "\n#{$!.class}: "
59
+ print "#{$!.message}\n"
60
+ end
61
+
62
+ def self.display_trace(line)
63
+ fn, ln = line.split(":")
64
+
65
+ puts " line: #{code(fn, ln)}"
66
+ puts " file: #{fn} +#{ln}"
67
+ end
68
+
69
+ class AssertionFailed < StandardError
70
+ end
71
+
72
+ class Scope
73
+ def initialize(&scope)
74
+ @scope = scope
75
+ end
76
+
77
+ def call
78
+ instance_eval(&@scope)
79
+ end
80
+ end
81
+ end
82
+
83
+ module Kernel
84
+ private
85
+
86
+ # Use Thread.current[:cutest] to store information about test preparation
87
+ # and setup.
88
+ Thread.current[:cutest] ||= { :prepare => [] }
89
+
90
+ # Shortcut to access Thread.current[:cutest].
91
+ def cutest
92
+ Thread.current[:cutest]
93
+ end
94
+
95
+ # Create an instance where the block will be evaluated. Recommended to improve
96
+ # isolation between tests.
97
+ def scope(name = nil, &block)
98
+ if !cutest[:scope] || cutest[:scope] == name
99
+ Cutest::Scope.new(&block).call
100
+ end
101
+ end
102
+
103
+ # Prepare the environment in order to run the tests. This method can be
104
+ # called many times, and each new block is appended to a list of
105
+ # preparation blocks. When a test is executed, all the preparation blocks
106
+ # are ran in the order they were declared. If called without a block, it
107
+ # returns the array of preparation blocks.
108
+ def prepare(&block)
109
+ cutest[:prepare] << block if block_given?
110
+ cutest[:prepare]
111
+ end
112
+
113
+ # Setup parameters for the tests. The block passed to setup is evaluated
114
+ # before running each test, and the result of the setup block is passed to
115
+ # the test as a parameter. If the setup and the tests are declared at the
116
+ # same level (in the global scope or in a sub scope), it is possible to use
117
+ # instance variables, but the parameter passing pattern is recommended to
118
+ # ensure there are no side effects.
119
+ #
120
+ # If the setup blocks are declared in the global scope and the tests are
121
+ # declared in sub scopes, the parameter passing usage is required.
122
+ #
123
+ # Setup blocks can be defined many times, but each new definition overrides
124
+ # the previous one. It is recommended to split the tests in many different
125
+ # files (the report is per file, not per assertion). Usually one setup
126
+ # block per file is enough, but nothing forbids having different scopes
127
+ # with different setup blocks.
128
+ def setup(&block)
129
+ cutest[:setup] = block if block_given?
130
+ cutest[:setup]
131
+ end
132
+
133
+ # Kernel includes a test method for performing tests on files.
134
+ undef test if defined? test
135
+
136
+ # Call the prepare and setup blocks before executing the test. Even
137
+ # though the assertions can live anywhere (it's not mandatory to put them
138
+ # inside test blocks), it is necessary to wrap them in test blocks in order
139
+ # to execute preparation and setup blocks.
140
+ def test(name = nil, &block)
141
+ cutest[:test] = name
142
+
143
+ if !cutest[:only] || cutest[:only] == name
144
+ prepare.each { |blk| blk.call }
145
+ block.call(setup && setup.call)
146
+ end
147
+
148
+ cutest[:test] = nil
149
+ end
150
+
151
+ # Assert that value is not nil or false.
152
+ def assert(value, msg = "expression returned #{value.inspect}")
153
+ flunk(msg) unless value
154
+ success
155
+ end
156
+
157
+ # Assert that actual and expected values are equal.
158
+ def assert_equal(actual, expected)
159
+ assert(actual == expected, "#{actual.inspect} != #{expected.inspect}")
160
+ end
161
+
162
+ # Assert that the block raises an expected exception.
163
+ def assert_raise(expected = Exception)
164
+ begin
165
+ yield
166
+ rescue expected => exception
167
+ exception
168
+ ensure
169
+ assert(exception.kind_of?(expected), "got #{exception.inspect} instead")
170
+ end
171
+ end
172
+
173
+ # Stop the tests and raise an error where the message is the last line
174
+ # executed before flunking.
175
+ def flunk(message = nil)
176
+ backtrace = caller.find { |line| line.include? 'top (required)' }
177
+ exception = Cutest::AssertionFailed.new(message)
178
+ exception.set_backtrace(backtrace)
179
+
180
+ raise exception
181
+ end
182
+
183
+ # Executed when an assertion succeeds.
184
+ def success
185
+ print "."
186
+ end
187
+ end
@@ -0,0 +1,9 @@
1
+ test "succeeds if the value is true" do
2
+ assert true
3
+ end
4
+
5
+ test "raises if the assertion fails" do
6
+ assert_raise(Cutest::AssertionFailed) do
7
+ assert false
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ test do
2
+ assert_equal 1, 1
3
+ end
4
+
5
+ test "raises if the assertion fails" do
6
+ assert_raise(Cutest::AssertionFailed) do
7
+ assert_equal 1, 2
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ test "catches default exception" do
2
+ assert_raise do
3
+ raise
4
+ end
5
+ end
6
+
7
+ test "catches the right exception" do
8
+ assert_raise(RuntimeError) do
9
+ raise RuntimeError
10
+ end
11
+ end
12
+
13
+ test "catches exceptions lower than StandardError" do
14
+ assert_raise(NotImplementedError) do
15
+ raise NotImplementedError
16
+ end
17
+ end
18
+
19
+ test "raises if nothing raised" do
20
+ assert_raise(Cutest::AssertionFailed) do
21
+ assert_raise {}
22
+ end
23
+ end
24
+
25
+ test "raises if the expectation is not met" do
26
+ assert_raise(Cutest::AssertionFailed) do
27
+ assert_raise(RuntimeError) do
28
+ raise ArgumentError
29
+ end
30
+ end
31
+ end
32
+
33
+ test "returns the exception" do
34
+ exception = assert_raise(RuntimeError) do
35
+ raise RuntimeError, "error"
36
+ end
37
+
38
+ assert_equal "error", exception.message
39
+ end
40
+
41
+ test "catches a custom exception" do
42
+ assert_raise do
43
+ raise Class.new(Exception)
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ def foo
2
+ raise "Oops"
3
+ end
4
+
5
+ test "some unhandled exception" do
6
+ foo
7
+ end
@@ -0,0 +1,7 @@
1
+ def assert_empty(string)
2
+ assert(string.empty?, "not empty")
3
+ end
4
+
5
+ test "failed custom assertion" do
6
+ assert_empty "foo"
7
+ end
@@ -0,0 +1,3 @@
1
+ test "failed with custom message" do
2
+ assert("hello".empty?, "not empty")
3
+ end
@@ -0,0 +1,3 @@
1
+ test "failed assertion" do
2
+ assert false
3
+ end
@@ -0,0 +1 @@
1
+ load("test/fixtures/failure.rb")
@@ -0,0 +1,15 @@
1
+ scope "another scope" do
2
+ test do
3
+ raise "This is not raised"
4
+ end
5
+ end
6
+
7
+ scope "scope" do
8
+ test "test" do
9
+ assert true
10
+ end
11
+
12
+ test do
13
+ raise "This is raised"
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ test "named success" do
2
+ assert true
3
+ end
4
+
5
+ assert false
@@ -0,0 +1,7 @@
1
+ def foo
2
+ raise "Invalid code"
3
+ end
4
+
5
+ test "external exceptions" do
6
+ assert true
7
+ end
@@ -0,0 +1,25 @@
1
+ prepare do
2
+ $foo = []
3
+ end
4
+
5
+ prepare do
6
+ $foo << true
7
+ end
8
+
9
+ test "all the prepare blocks are called" do
10
+ assert $foo == [true]
11
+ end
12
+
13
+ prepare do
14
+ $foo << false
15
+ end
16
+
17
+ test "and are cumulative" do
18
+ assert $foo == [true, false]
19
+ end
20
+
21
+ scope do
22
+ test "and run inside scopes" do
23
+ assert $foo = [true, false]
24
+ end
25
+ end
@@ -0,0 +1,110 @@
1
+ test "output of successful run" do
2
+ expected = ".\n"
3
+
4
+ out = %x{./bin/cutest test/fixtures/success.rb}
5
+
6
+ assert_equal(expected, out)
7
+ end
8
+
9
+ test "exit code of successful run" do
10
+ %x{./bin/cutest test/fixtures/success.rb}
11
+ assert_equal 0, $?.to_i
12
+ end
13
+
14
+ test "output of failed run" do
15
+ expected = "\n" +
16
+ " test: failed assertion\n" +
17
+ " line: assert false\n" +
18
+ " file: test/fixtures/failure.rb +2\n\n" +
19
+ "Cutest::AssertionFailed: expression returned false\n\n"
20
+
21
+ out = %x{./bin/cutest test/fixtures/failure.rb}
22
+
23
+ assert_equal(expected, out)
24
+ end
25
+
26
+ test "output of failed run" do
27
+ expected = "\n" +
28
+ " test: some unhandled exception\n" +
29
+ " line: raise \"Oops\"\n" +
30
+ " file: test/fixtures/exception.rb +2\n\n" +
31
+ "RuntimeError: Oops\n\n"
32
+
33
+ out = %x{./bin/cutest test/fixtures/exception.rb}
34
+
35
+ assert_equal(expected, out)
36
+ end
37
+
38
+ test "exit code of failed run" do
39
+ %x{./bin/cutest test/fixtures/failure.rb}
40
+
41
+ assert $?.to_i != 0
42
+ end
43
+
44
+ test "output of an assertion with custom message" do
45
+ expected = "\n" +
46
+ " test: failed with custom message\n" +
47
+ " line: assert(\"hello\".empty?, \"not empty\")\n" +
48
+ " file: test/fixtures/fail_custom_message.rb +2\n\n" +
49
+ "Cutest::AssertionFailed: not empty\n\n"
50
+
51
+ out = %x{./bin/cutest test/fixtures/fail_custom_message.rb}
52
+
53
+ assert_equal(expected, out)
54
+ end
55
+
56
+ test "output of custom assertion" do
57
+ expected = "\n" +
58
+ " test: failed custom assertion\n" +
59
+ " line: assert_empty \"foo\"\n" +
60
+ " file: test/fixtures/fail_custom_assertion.rb +6\n\n" +
61
+ "Cutest::AssertionFailed: not empty\n\n"
62
+
63
+ out = %x{./bin/cutest test/fixtures/fail_custom_assertion.rb}
64
+
65
+ assert_equal(expected, out)
66
+ end
67
+
68
+ test "output of failure in nested file" do
69
+ expected = "\n" +
70
+ " test: failed assertion\n" +
71
+ " line: assert false\n" +
72
+ " file: test/fixtures/failure.rb +2\n\n" +
73
+ "Cutest::AssertionFailed: expression returned false\n\n"
74
+
75
+ out = %x{./bin/cutest test/fixtures/failure_in_loaded_file.rb}
76
+
77
+ assert_equal(expected, out)
78
+ end
79
+
80
+ test "output of failure outside block" do
81
+ expected = ".\n" +
82
+ " test: \n" +
83
+ " line: assert false\n" +
84
+ " file: test/fixtures/outside_block.rb +5\n\n" +
85
+ "Cutest::AssertionFailed: expression returned false\n\n"
86
+
87
+ out = %x{./bin/cutest test/fixtures/outside_block.rb}
88
+
89
+ assert_equal(expected, out)
90
+ end
91
+
92
+ test "only runs given scope name" do
93
+ out = %x{./bin/cutest test/fixtures/only_run_given_scope_name.rb -s scope}
94
+
95
+ assert out =~ /This is raised/
96
+ end
97
+
98
+ test "runs by given scope and test names" do
99
+ %x{./bin/cutest test/fixtures/only_run_given_scope_name.rb -s scope -o test}
100
+
101
+ assert_equal 0, $?.to_i
102
+ end
103
+
104
+ test "only prints the version" do
105
+ expected = "#{Cutest::VERSION}\n"
106
+
107
+ out = %x{./bin/cutest test/fixtures/success.rb -v}
108
+
109
+ assert_equal(expected, out)
110
+ end
@@ -0,0 +1,27 @@
1
+ @bar = true
2
+
3
+ scope do
4
+ @foo = true
5
+
6
+ test "something" do
7
+ assert defined?(@foo)
8
+ assert !defined?(@bar)
9
+ end
10
+ end
11
+
12
+ scope do
13
+ test "something" do
14
+ assert !defined?(@foo)
15
+ assert !defined?(@bar)
16
+ end
17
+ end
18
+
19
+ scope do
20
+ @baz = true
21
+
22
+ scope do
23
+ test "something" do
24
+ assert !defined?(@baz)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ setup do
2
+ {:a => 23, :b => 43}
3
+ end
4
+
5
+ test "should receive the result of the setup block as a parameter" do |params|
6
+ assert params == {:a => 23, :b => 43}
7
+ end
8
+
9
+ test "if the params are modified..." do |params|
10
+ params[:a] = nil
11
+ end
12
+
13
+ test "...it should preserve the original values from the setup" do |params|
14
+ assert_equal 23, params[:a]
15
+ end
16
+
17
+ setup do
18
+ "Hello world!"
19
+ end
20
+
21
+ test "only the most recently defined setup block is executed" do |value|
22
+ assert "Hello world!" == value
23
+ end
24
+
25
+ scope do
26
+ test "works inside scopes too" do |value|
27
+ assert "Hello world!" == value
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: clap 1.0.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "clap".freeze
6
+ s.version = "1.0.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Michel Martens".freeze]
11
+ s.date = "2012-03-29"
12
+ s.description = "Clap is a small library that can be bundled with your command line application. It covers the simple case of executing code based on the flags or parameters passed.".freeze
13
+ s.email = ["michel@soveran.com".freeze]
14
+ s.homepage = "http://github.com/soveran/clap".freeze
15
+ s.rubygems_version = "2.6.14".freeze
16
+ s.summary = "Command line argument parsing for simple applications.".freeze
17
+
18
+ s.installed_by_version = "2.6.14" if s.respond_to? :installed_by_version
19
+
20
+ if s.respond_to? :specification_version then
21
+ s.specification_version = 3
22
+
23
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
+ s.add_development_dependency(%q<cutest>.freeze, [">= 0"])
25
+ else
26
+ s.add_dependency(%q<cutest>.freeze, [">= 0"])
27
+ end
28
+ else
29
+ s.add_dependency(%q<cutest>.freeze, [">= 0"])
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: cutest 1.2.3 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "cutest".freeze
6
+ s.version = "1.2.3"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Damian Janowski".freeze, "Michel Martens".freeze, "Cyril David".freeze]
11
+ s.date = "2015-12-04"
12
+ s.description = "Run tests in separate processes to avoid shared state.".freeze
13
+ s.email = ["djanowski@dimaion.com".freeze, "michel@soveran.com".freeze, "me@cyrildavid.com".freeze]
14
+ s.executables = ["cutest".freeze]
15
+ s.files = ["bin/cutest".freeze]
16
+ s.homepage = "https://github.com/djanowski/cutest".freeze
17
+ s.licenses = ["MIT".freeze]
18
+ s.rubygems_version = "2.6.14".freeze
19
+ s.summary = "Forking tests.".freeze
20
+
21
+ s.installed_by_version = "2.6.14" if s.respond_to? :installed_by_version
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 4
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<clap>.freeze, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<clap>.freeze, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<clap>.freeze, [">= 0"])
33
+ end
34
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ polizia (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ clap (1.0.0)
10
+ cutest (1.2.3)
11
+ clap
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ cutest
18
+ polizia!
19
+
20
+ BUNDLED WITH
21
+ 1.15.4
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ desc 'open irb in gs context'
2
+ task :console do
3
+ sh 'gs irb'
4
+ end
5
+
6
+ task :default do
7
+ sh 'rake -T'
8
+ end
9
+
10
+ desc 'installs gems'
11
+ task :install do
12
+ sh 'mkdir -p .gs & gs bundle install --system'
13
+ end
14
+
15
+ desc 'tests the given [test].rb'
16
+ task :test, :name do |t, args|
17
+ name = args[:name] || '*'
18
+
19
+ sh "gs cutest -r ./test/#{name}.rb"
20
+ end
data/lib/polizia.rb ADDED
@@ -0,0 +1,29 @@
1
+ class Polizia
2
+ VERSION = '1.0.0'
3
+
4
+ attr_reader :user
5
+
6
+ def initialize(user)
7
+ @user = user
8
+ end
9
+
10
+ def create?
11
+ false
12
+ end
13
+
14
+ def index?
15
+ false
16
+ end
17
+
18
+ def show?(arg = nil)
19
+ false
20
+ end
21
+
22
+ def update?(arg = nil)
23
+ false
24
+ end
25
+
26
+ def delete?(arg = nil)
27
+ false
28
+ end
29
+ end
data/polizia.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ require_relative './lib/polizia'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'polizia'
5
+ s.summary = 'Polizia'
6
+ s.version = Polizia::VERSION
7
+ s.authors = ['Steve Weiss']
8
+ s.email = ['weissst@mail.gvsu.edu']
9
+ s.homepage = 'https://github.com/sirscriptalot/polizia'
10
+ s.license = 'MIT'
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_development_dependency 'cutest', '~> 1.2'
14
+ end
data/test/all.rb ADDED
@@ -0,0 +1,25 @@
1
+ require_relative '../lib/polizia'
2
+
3
+ setup do
4
+ Polizia.new(nil)
5
+ end
6
+
7
+ test '#create?' do |policy|
8
+ assert !policy.create?
9
+ end
10
+
11
+ test '#index?' do |policy|
12
+ assert !policy.index?
13
+ end
14
+
15
+ test '#show?' do |policy|
16
+ assert !policy.show?
17
+ end
18
+
19
+ test '#update?' do |policy|
20
+ assert !policy.update?
21
+ end
22
+
23
+ test '#delete?' do |policy|
24
+ assert !policy.delete?
25
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polizia
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Weiss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cutest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ description:
28
+ email:
29
+ - weissst@mail.gvsu.edu
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gs/bin/cutest"
35
+ - ".gs/cache/clap-1.0.0.gem"
36
+ - ".gs/cache/cutest-1.2.3.gem"
37
+ - ".gs/gems/clap-1.0.0/LICENSE"
38
+ - ".gs/gems/clap-1.0.0/Rakefile"
39
+ - ".gs/gems/clap-1.0.0/clap.gemspec"
40
+ - ".gs/gems/clap-1.0.0/lib/clap.rb"
41
+ - ".gs/gems/clap-1.0.0/test/clap_test.rb"
42
+ - ".gs/gems/cutest-1.2.3/.gitignore"
43
+ - ".gs/gems/cutest-1.2.3/CHANGELOG.md"
44
+ - ".gs/gems/cutest-1.2.3/LICENSE"
45
+ - ".gs/gems/cutest-1.2.3/Makefile"
46
+ - ".gs/gems/cutest-1.2.3/README.markdown"
47
+ - ".gs/gems/cutest-1.2.3/bin/cutest"
48
+ - ".gs/gems/cutest-1.2.3/cutest.gemspec"
49
+ - ".gs/gems/cutest-1.2.3/lib/cutest.rb"
50
+ - ".gs/gems/cutest-1.2.3/test/assert.rb"
51
+ - ".gs/gems/cutest-1.2.3/test/assert_equal.rb"
52
+ - ".gs/gems/cutest-1.2.3/test/assert_raise.rb"
53
+ - ".gs/gems/cutest-1.2.3/test/fixtures/exception.rb"
54
+ - ".gs/gems/cutest-1.2.3/test/fixtures/fail_custom_assertion.rb"
55
+ - ".gs/gems/cutest-1.2.3/test/fixtures/fail_custom_message.rb"
56
+ - ".gs/gems/cutest-1.2.3/test/fixtures/failure.rb"
57
+ - ".gs/gems/cutest-1.2.3/test/fixtures/failure_in_loaded_file.rb"
58
+ - ".gs/gems/cutest-1.2.3/test/fixtures/only_run_given_scope_name.rb"
59
+ - ".gs/gems/cutest-1.2.3/test/fixtures/outside_block.rb"
60
+ - ".gs/gems/cutest-1.2.3/test/fixtures/success.rb"
61
+ - ".gs/gems/cutest-1.2.3/test/prepare.rb"
62
+ - ".gs/gems/cutest-1.2.3/test/run.rb"
63
+ - ".gs/gems/cutest-1.2.3/test/scopes.rb"
64
+ - ".gs/gems/cutest-1.2.3/test/setup.rb"
65
+ - ".gs/specifications/clap-1.0.0.gemspec"
66
+ - ".gs/specifications/cutest-1.2.3.gemspec"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - Rakefile
70
+ - lib/polizia.rb
71
+ - polizia.gemspec
72
+ - test/all.rb
73
+ homepage: https://github.com/sirscriptalot/polizia
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.14
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Polizia
97
+ test_files: []