catechism 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9db9fd7efc9a513e2ead19f022759e11fbd9eb5
4
+ data.tar.gz: 46a5bef2912e4223340f1ab8d177a8d4641f9055
5
+ SHA512:
6
+ metadata.gz: d54c417d7f68b765f8ca307d4629249fa93a40f2724b6450aa16d48f754bb6b50c8ce354e400199767f9b6f1fcc2b8b8abeab74c06cb545a660e4c71ef9f4e3a
7
+ data.tar.gz: d504e27f538c3118329ca69ed43bc29d6a4f41a88aec45c57bcddca3e562a3405265c1f619afd13abd7a5c68c3339be51454dbd1a1093ad6025784994b21f54b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ catechism
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ guard :shell do
4
+ watch(/^trials\/(.*)_trial\.rb/) {|m| `bin/catechism run_trial #{m[0]}` }
5
+ watch(/^(lib\/.*)\.rb/) {|m| `bin/catechism run_trial trials/#{m[1]}_trial.rb` }
6
+ end
@@ -0,0 +1,49 @@
1
+ Catechism
2
+ =========
3
+
4
+ Catechism is a very small test framework for Ruby.
5
+
6
+
7
+ Prerequisites
8
+ -------------
9
+
10
+ * Ruby 2.0.0
11
+ * A Unix environment
12
+
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'catechism'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install catechism
28
+
29
+
30
+ Usage
31
+ -----
32
+
33
+ Create a `trials` directory in the root of your project.
34
+
35
+ Create files in any path underneath it ending in `_trial.rb`. Examples can be found in `trials/lib/catechism`.
36
+
37
+ Then, run your test suite:
38
+
39
+ $ catechism
40
+
41
+
42
+ Contributing
43
+ ------------
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "catechism"
5
+ Catechism::Cli.start
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'catechism/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'catechism'
8
+ spec.version = Catechism::VERSION
9
+ spec.authors = ['Doc Ritezel and Sarah Mei']
10
+ spec.email = ['pair+doc+sarah@ministryofvelocity.com']
11
+ spec.description = 'An object-oriented testing framework'
12
+ spec.summary = 'Put your code through an object-oriented trial by fire.'
13
+ spec.homepage = 'https://github.com/aosabook/500lines/catechism'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^trials/})
19
+ spec.require_paths = ['lib']
20
+ spec.bindir = 'bin'
21
+
22
+ spec.add_dependency 'thor'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'gem-release'
26
+ spec.add_development_dependency 'guard-shell'
27
+ end
@@ -0,0 +1,5 @@
1
+ require "catechism/version"
2
+ require "core_ext/object"
3
+ require "catechism/describe_block"
4
+ require "catechism/subject_wrapper"
5
+ require "catechism/cli"
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+
3
+ class Catechism::Cli < Thor
4
+ desc 'run_trial TRIAL', 'Run the given trial'
5
+ def run_trial(trial_path)
6
+ Kernel.system("bundle exec ruby #{trial_path}") && puts("#{trial_path} was successful.")
7
+ end
8
+
9
+ desc 'run_all_trials', 'Run all trials in the current path'
10
+ def run_all_trials
11
+ Dir.glob('trials/**/*_trial.rb') { |trial_path| run_trial(trial_path) }
12
+ end
13
+
14
+ default_task :run_all_trials
15
+ end
@@ -0,0 +1,7 @@
1
+ require "catechism/it_block"
2
+
3
+ class Catechism::DescribeBlock < Struct.new(:description)
4
+ def it(description, &block)
5
+ Catechism::ItBlock.new(description, self).instance_eval(&block) if block_given?
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class Catechism::ItBlock < Struct.new(:description, :current_context)
2
+ def expect(subject = nil, &block)
3
+ subject = block if block_given?
4
+ Catechism::SubjectWrapper.new(subject)
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ module Catechism
2
+ module Matchers
3
+ class Equal < Struct.new(:subject, :expectation, :negated)
4
+ def equal?
5
+ subject == expectation
6
+ end
7
+
8
+ def valid?
9
+ equal? ^ negated
10
+ end
11
+
12
+ def failure_message
13
+ if negated
14
+ "#{subject} equals #{expected}"
15
+ else
16
+ "#{subject} does not equal #{expected}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Catechism::Matchers
2
+ class RaiseError < Struct.new(:subject, :negated)
3
+ def raised?
4
+ begin
5
+ subject.call
6
+ rescue StandardError => e
7
+ return true
8
+ end
9
+ false
10
+ end
11
+
12
+ def valid?
13
+ raised? ^ negated
14
+ end
15
+
16
+ def failure_message
17
+ if negated
18
+ "Expected no error to be raised, but an error was raised"
19
+ else
20
+ "Expected error to be raised, but no error was raised"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ module Catechism::Matchers
2
+ class Send < Struct.new(:subject, :method_name, :negated)
3
+ attr_reader :destination, :arguments
4
+
5
+ def to(destination)
6
+ @destination = destination
7
+ raise failure_message unless valid?
8
+ end
9
+
10
+ def with(*arguments)
11
+ @arguments = arguments
12
+ self
13
+ end
14
+
15
+ def valid?
16
+ called = false
17
+ send_matcher = self
18
+ destination.class.send(:define_method, method_name) do |*args|
19
+ if !send_matcher.arguments.nil?
20
+ called = send_matcher.arguments == args
21
+ else
22
+ called = true
23
+ end
24
+ end
25
+ subject.call
26
+ called ^ negated
27
+ end
28
+
29
+ def failure_message
30
+ if negated
31
+ "Expected #{destination} not to receive #{method_name}, but got it anyway"
32
+ else
33
+ "Expected #{method_name} on #{destination}, but was not received"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require 'catechism/matchers/equal'
2
+ require 'catechism/matchers/raise_error'
3
+ require 'catechism/matchers/send'
4
+
5
+ class Catechism::SubjectWrapper < Struct.new(:subject)
6
+ attr_reader :negated
7
+
8
+ def to_equal(expected)
9
+ matcher = Catechism::Matchers::Equal.new(subject, expected, negated)
10
+ raise matcher.failure_message unless matcher.valid?
11
+ end
12
+
13
+ def to_be_nil
14
+ matcher = Catechism::Matchers::Equal.new(subject, nil, negated)
15
+ raise matcher.failure_message unless matcher.valid?
16
+ end
17
+
18
+ def to_raise_error
19
+ matcher = Catechism::Matchers::RaiseError.new(subject, negated)
20
+ raise matcher.failure_message unless matcher.valid?
21
+ end
22
+
23
+ def to_send(method_name)
24
+ Catechism::Matchers::Send.new(subject, method_name, negated)
25
+ end
26
+
27
+ def not
28
+ @negated = true
29
+ self
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Catechism
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ class Object
2
+ def describe(description, &block)
3
+ Catechism::DescribeBlock.new(description).instance_eval(&block) if block_given?
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'catechism'
2
+
3
+ describe Catechism::Cli do
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'catechism'
2
+
3
+ describe 'using contexts' do
4
+ it 'lets you group tests with describes' do
5
+ expect(current_context.description).to_equal('using contexts')
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require 'catechism'
2
+
3
+ describe 'using catechism matchers' do
4
+ class Harness; end
5
+
6
+ it 'lets you test equality' do
7
+ expect(1).to_equal(1)
8
+ expect(2).not.to_equal(1)
9
+ end
10
+
11
+ it 'lets you test nilness' do
12
+ expect(nil).to_be_nil
13
+ expect(1).not.to_be_nil
14
+ end
15
+
16
+ it 'lets you test exception raising' do
17
+ expect { raise 'hands' }.to_raise_error
18
+ expect { 3 + 1 }.not.to_raise_error
19
+ end
20
+
21
+ it 'lets you test that an instance receives a message' do
22
+ tacos = Harness.new
23
+ expect { tacos.sauce }.to_send(:sauce).to(tacos)
24
+ expect { tacos.to_s }.not.to_send(:sauce).to(tacos)
25
+ end
26
+
27
+ it 'lets you test that a class receives a message' do
28
+ expect { Harness.to_s }.to_send(:to_s).to(Harness)
29
+ expect { Harness.inspect }.not.to_send(:to_s).to(Harness)
30
+ end
31
+
32
+ it 'lets you test that an instance receives a message with arguments' do
33
+ pants = Object.new
34
+ expect {
35
+ pants.tuck_into('socks')
36
+ }.to_send(:tuck_into).with('socks').to(pants)
37
+
38
+ expect {
39
+ pants.tuck_into('ears')
40
+ }.not.to_send(:tuck_into).with('socks').to(pants)
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ require 'catechism'
2
+
3
+ describe 'the number of lines' do
4
+ it 'stays under 500' do
5
+ lib_files = Dir.glob(File.expand_path('../../lib/**/*.rb', __FILE__))
6
+ bin_files = Dir.glob(File.expand_path('../../bin/*', __FILE__))
7
+ trial_files = Dir.glob(File.expand_path('../../trials/**/*.rb', __FILE__))
8
+
9
+ lines = (lib_files + bin_files + trial_files).reduce(0) do |line_count, filename|
10
+ line_count + IO.readlines(filename).size
11
+ end
12
+
13
+ expect(lines < 500).to_equal(true)
14
+ puts "Current number of lines is #{lines}"
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catechism
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Doc Ritezel and Sarah Mei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gem-release
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-shell
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: An object-oriented testing framework
70
+ email:
71
+ - pair+doc+sarah@ministryofvelocity.com
72
+ executables:
73
+ - catechism
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .ruby-gemset
79
+ - .ruby-version
80
+ - Gemfile
81
+ - Guardfile
82
+ - README.md
83
+ - bin/catechism
84
+ - catechism.gemspec
85
+ - lib/catechism.rb
86
+ - lib/catechism/cli.rb
87
+ - lib/catechism/describe_block.rb
88
+ - lib/catechism/it_block.rb
89
+ - lib/catechism/matchers/equal.rb
90
+ - lib/catechism/matchers/raise_error.rb
91
+ - lib/catechism/matchers/send.rb
92
+ - lib/catechism/subject_wrapper.rb
93
+ - lib/catechism/version.rb
94
+ - lib/core_ext/object.rb
95
+ - trials/lib/catechism/cli_trial.rb
96
+ - trials/lib/catechism/context_trial.rb
97
+ - trials/lib/catechism/matcher_trial.rb
98
+ - trials/line_trial.rb
99
+ homepage: https://github.com/aosabook/500lines/catechism
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.0.14
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Put your code through an object-oriented trial by fire.
123
+ test_files:
124
+ - trials/lib/catechism/cli_trial.rb
125
+ - trials/lib/catechism/context_trial.rb
126
+ - trials/lib/catechism/matcher_trial.rb
127
+ - trials/line_trial.rb