aktion_test 0.2.2 → 0.3.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.
- data/CHANGELOG.md +6 -0
- data/lib/aktion_test/matchers/file_system/directory_contains.rb +0 -2
- data/lib/aktion_test/matchers/file_system/directory_existance.rb +0 -2
- data/lib/aktion_test/matchers/file_system/file_contains.rb +0 -2
- data/lib/aktion_test/matchers/file_system/file_existance.rb +0 -2
- data/lib/aktion_test/module/aktion_test.rb +14 -11
- data/lib/aktion_test/module/base.rb +22 -0
- data/lib/aktion_test/module/factory_girl.rb +5 -7
- data/lib/aktion_test/module/faker.rb +2 -4
- data/lib/aktion_test/module/rspec.rb +5 -9
- data/lib/aktion_test/module/simplecov.rb +8 -3
- data/lib/aktion_test/module/timecop.rb +6 -4
- data/lib/aktion_test/spec_helper.rb +35 -41
- data/lib/aktion_test/support/class_builder.rb +2 -2
- data/lib/aktion_test/version.rb +1 -1
- data/spec/aktion_test/spec_helper_spec.rb +77 -23
- data/spec/matchers/base_spec.rb +32 -4
- data/spec/spec_helper.rb +6 -1
- metadata +6 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# v0.3.0
|
2
|
+
* New spec helper interface, more OOPish this time
|
3
|
+
* Modules receive the spec helper instance in their initialize to load dependencies
|
4
|
+
* Improve coverage
|
5
|
+
* AktionLab module now loads SimpleCov as it initializes
|
6
|
+
|
1
7
|
# v0.2.2
|
2
8
|
* More spec helper improvements
|
3
9
|
* Update factory girl to 4.2
|
@@ -1,18 +1,21 @@
|
|
1
1
|
module AktionTest
|
2
2
|
module Module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class AktionTest < Base
|
4
|
+
def initialize(spec, options={})
|
5
|
+
super
|
6
|
+
spec.use :Simplecov
|
7
|
+
end
|
8
|
+
|
9
|
+
def prepare
|
7
10
|
require 'aktion_test/matchers/base'
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
13
|
+
def configure
|
14
|
+
rspec.include Support::ClassBuilder
|
15
|
+
rspec.include Matchers::FileSystem::DirectoryExistance
|
16
|
+
rspec.include Matchers::FileSystem::FileExistance
|
17
|
+
rspec.include Matchers::FileSystem::DirectoryContains
|
18
|
+
rspec.include Matchers::FileSystem::FileContains
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AktionTest
|
2
|
+
module Module
|
3
|
+
class Base
|
4
|
+
def initialize(spec, options={})
|
5
|
+
@options, @spec = options, spec
|
6
|
+
@rspec = ::RSpec.configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def prepare
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure
|
13
|
+
end
|
14
|
+
|
15
|
+
def cleanup
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
attr_reader :rspec, :options
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module AktionTest
|
2
2
|
module Module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
included do |spec_helper|
|
3
|
+
class FactoryGirl < Base
|
4
|
+
def prepare
|
7
5
|
require 'factory_girl'
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
def configure
|
9
|
+
rspec.include ::FactoryGirl::Syntax::Methods
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -1,14 +1,10 @@
|
|
1
1
|
module AktionTest
|
2
2
|
module Module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
-
config.run_all_when_everything_filtered = true
|
10
|
-
config.order = 'random'
|
11
|
-
end
|
3
|
+
class RSpec < Base
|
4
|
+
def configure
|
5
|
+
rspec.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
rspec.run_all_when_everything_filtered = true
|
7
|
+
rspec.order = 'random'
|
12
8
|
end
|
13
9
|
end
|
14
10
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module AktionTest
|
2
2
|
module Module
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class Simplecov < Base
|
4
|
+
def initialize(spec, options={})
|
5
|
+
super
|
6
|
+
require 'simplecov'
|
7
|
+
::SimpleCov.start do
|
8
|
+
add_filter '/spec/'
|
9
|
+
end
|
10
|
+
end
|
6
11
|
end
|
7
12
|
end
|
8
13
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module AktionTest
|
2
2
|
module Module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
included do |spec_helper|
|
3
|
+
class Timecop < Base
|
4
|
+
def prepare
|
7
5
|
require 'timecop'
|
8
6
|
end
|
7
|
+
|
8
|
+
def configure
|
9
|
+
rspec.after { ::Timecop.return }
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,27 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'aktion_test/module/base'
|
2
2
|
|
3
3
|
module AktionTest
|
4
4
|
class SpecHelper
|
5
|
-
|
6
|
-
|
7
|
-
attr_reader :modules, :options, :scope
|
5
|
+
attr_reader :modules, :options
|
6
|
+
attr_writer :scope
|
8
7
|
|
9
8
|
class << self
|
10
|
-
def
|
11
|
-
|
12
|
-
|
9
|
+
def build(&block)
|
10
|
+
new.tap do |sh|
|
11
|
+
if block_given?
|
12
|
+
sh.instance_eval(&block)
|
13
|
+
sh.compile!
|
14
|
+
end
|
13
15
|
end
|
14
|
-
|
15
|
-
instance.instance_eval(&block) if block_given?
|
16
|
-
|
17
|
-
instance.modules.each{|mod| include mod}
|
18
|
-
end
|
19
|
-
|
20
|
-
def add_module(name, options={})
|
21
|
-
end
|
22
|
-
|
23
|
-
def add_modules(*names)
|
24
|
-
names.each{|name| add_module(name)}
|
25
16
|
end
|
26
17
|
end
|
27
18
|
|
@@ -31,41 +22,44 @@ module AktionTest
|
|
31
22
|
|
32
23
|
def reset
|
33
24
|
@modules = []
|
34
|
-
@options = {}
|
35
25
|
@scope = %w(AktionTest Module)
|
36
26
|
end
|
37
27
|
|
38
|
-
def
|
39
|
-
eval "defined? AktionTest::Module::#{name}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def load(*names)
|
28
|
+
def use(*names)
|
43
29
|
options = names.extract_options!
|
30
|
+
return names.each {|name| use name} if names.many?
|
44
31
|
|
45
|
-
names.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
name = names.first
|
33
|
+
|
34
|
+
klass = case name
|
35
|
+
when Class then name
|
36
|
+
when /^::/ then name.constantize
|
37
|
+
else "#{@scope.join('::')}::#{name}".constantize
|
50
38
|
end
|
51
|
-
end
|
52
39
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
40
|
+
unless klass.ancestors.include? AktionTest::Module::Base
|
41
|
+
raise ArgumentError.new("#{klass.name} must inherit from AktionTest::Module::Base")
|
42
|
+
end
|
43
|
+
|
44
|
+
modules << klass.new(self, options)
|
57
45
|
end
|
58
46
|
|
59
|
-
|
47
|
+
def scope(name='')
|
48
|
+
return @scope if name.blank?
|
49
|
+
raise ArgumentError.new("A block is required when applying a temporary scope") unless block_given?
|
60
50
|
|
61
|
-
def load_constant(name)
|
62
|
-
name = "#{self.scope.join('::')}::#{name}"
|
63
51
|
begin
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
scope << name
|
53
|
+
yield
|
54
|
+
ensure
|
55
|
+
scope.pop
|
68
56
|
end
|
69
57
|
end
|
58
|
+
|
59
|
+
def compile!
|
60
|
+
modules.each &:prepare
|
61
|
+
modules.each &:configure
|
62
|
+
modules.each &:cleanup
|
63
|
+
end
|
70
64
|
end
|
71
65
|
end
|
@@ -9,11 +9,11 @@ module AktionTest
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def define_class(class_name, base = Object, &block)
|
12
|
+
def define_class(class_name, base = Object, scope = Object, &block)
|
13
13
|
class_name = class_name.to_s.camelize
|
14
14
|
|
15
15
|
Class.new(base).tap do |constant_class|
|
16
|
-
|
16
|
+
scope.const_set(class_name, constant_class)
|
17
17
|
constant_class.unloadable
|
18
18
|
constant_class.class_eval(&block) if block_given?
|
19
19
|
constant_class.reset_column_information if constant_class.respond_to? :reset_column_information
|
data/lib/aktion_test/version.rb
CHANGED
@@ -1,36 +1,90 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AktionTest::SpecHelper do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
describe '::build' do
|
5
|
+
it 'instance evals the given block within the context of a spec helper' do
|
6
|
+
be_kind_of_spec_helper = be_kind_of described_class
|
7
|
+
described_class.build { self.should be_kind_of_spec_helper }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns the spec helper instance used in the instance eval' do
|
11
|
+
sh1 = nil
|
12
|
+
sh2 = described_class.build {sh1 = self}
|
13
|
+
sh1.should == sh2
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '::new' do
|
18
|
+
its(:modules) { should be_a Array }
|
19
|
+
its(:modules) { should be_empty }
|
20
|
+
its(:scope) { should == %w(AktionTest Module) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#use' do
|
24
|
+
before do
|
25
|
+
define_class 'TestMod', AktionTest::Module::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates a new module of the given class' do
|
29
|
+
subject.use TestMod
|
30
|
+
subject.modules.first.should be_kind_of TestMod
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates a new module of the given string without a scope' do
|
34
|
+
subject.use '::TestMod'
|
35
|
+
subject.modules.first.should be_kind_of TestMod
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'creates a new module of the given symbol with a scope' do
|
39
|
+
module TestModule; end
|
40
|
+
define_class 'TestMod', AktionTest::Module::Base, TestModule
|
41
|
+
subject.scope = ['TestModule']
|
42
|
+
subject.use :TestMod
|
43
|
+
subject.modules.first.should be_kind_of TestModule::TestMod
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'forwards any options to the new module' do
|
47
|
+
TestMod.should_receive(:new).with(kind_of(AktionTest::SpecHelper), :with => :options)
|
48
|
+
subject.use TestMod, :with => :options
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'raises an ArgumentError if the class is not a base module' do
|
52
|
+
define_class 'NonMod'
|
53
|
+
expect { subject.use NonMod }.to raise_error(ArgumentError, /must inherit from AktionTest::Module::Base/)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'can load multiple modules at once' do
|
57
|
+
define_class 'AnotherMod', AktionTest::Module::Base
|
58
|
+
subject.use TestMod, AnotherMod
|
59
|
+
subject.modules.map(&:class).should include(TestMod, AnotherMod)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#scope' do
|
64
|
+
it 'allows temporarily changing the scope' do
|
65
|
+
subject.scope 'TestScope' do
|
66
|
+
subject.scope.should == %w(AktionTest Module TestScope)
|
16
67
|
end
|
17
68
|
subject.scope.should == %w(AktionTest Module)
|
18
69
|
end
|
19
|
-
end
|
20
70
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
subject.scope << 'Baz'
|
71
|
+
it 'returns the current scope with no arguments' do
|
72
|
+
subject.scope.should == %w(AktionTest Module)
|
73
|
+
end
|
25
74
|
|
26
|
-
|
75
|
+
it 'raises an ArgumentError if no block is given and a scope is named' do
|
76
|
+
expect { subject.scope 'TestScope' }.to raise_error(ArgumentError, /block is required/)
|
77
|
+
end
|
27
78
|
|
28
|
-
|
79
|
+
it 'resets the scope even if an error occurs in the block' do
|
80
|
+
begin
|
81
|
+
subject.scope 'TestScope' do
|
82
|
+
raise 'an error'
|
83
|
+
end
|
84
|
+
rescue
|
85
|
+
end
|
29
86
|
|
30
|
-
subject.
|
31
|
-
Baz.autoload?(:Bar).should be_nil
|
32
|
-
subject.options.should have_key(:Bar)
|
33
|
-
subject.options[:Bar].should == {:test => :option}
|
87
|
+
subject.scope.should == %w(AktionTest Module)
|
34
88
|
end
|
35
89
|
end
|
36
90
|
end
|
data/spec/matchers/base_spec.rb
CHANGED
@@ -2,13 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe AktionTest::Matchers::Base do
|
4
4
|
before :each do
|
5
|
-
|
6
|
-
def expectation;
|
7
|
-
def problems_for_should;
|
5
|
+
define_class('Matcher', described_class) do
|
6
|
+
def expectation; "an expectation"; end
|
7
|
+
def problems_for_should; "\na problem\nanother problem"; end
|
8
8
|
def problems_for_should_not; "\na problem\nanother problem"; end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
define_class 'EmptyMatcher', described_class
|
12
|
+
|
13
|
+
@matcher = ::Matcher.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'provides a warning that the expectation has not been set' do
|
17
|
+
matcher = EmptyMatcher.new
|
18
|
+
matcher.stub(:perform_match! => false)
|
19
|
+
matcher.matches? nil
|
20
|
+
matcher.failure_message.should =~ /Override expectation to provide expectation details/
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'raises an error if perform_match! is not overriden' do
|
24
|
+
matcher = EmptyMatcher.new
|
25
|
+
expect { matcher.matches? nil }.to raise_error(/Override perform_match!/)
|
12
26
|
end
|
13
27
|
|
14
28
|
describe '#failure_message' do
|
@@ -32,6 +46,13 @@ describe AktionTest::Matchers::Base do
|
|
32
46
|
@matcher.matches? nil
|
33
47
|
expect { @matcher.failure_message }.to raise_error(RuntimeError, /failure message while/)
|
34
48
|
end
|
49
|
+
|
50
|
+
it 'provides a warning the failure message has not been set' do
|
51
|
+
matcher = EmptyMatcher.new
|
52
|
+
matcher.stub(:perform_match! => false)
|
53
|
+
matcher.matches? nil
|
54
|
+
matcher.failure_message.should =~ /Override problem_for_should /
|
55
|
+
end
|
35
56
|
end
|
36
57
|
|
37
58
|
describe '#negative_failure_message' do
|
@@ -55,5 +76,12 @@ describe AktionTest::Matchers::Base do
|
|
55
76
|
@matcher.matches? nil
|
56
77
|
expect { @matcher.negative_failure_message }.to raise_error(RuntimeError, /negative failure message while/)
|
57
78
|
end
|
79
|
+
|
80
|
+
it 'provides a warning the failure message has not been set' do
|
81
|
+
matcher = EmptyMatcher.new
|
82
|
+
matcher.stub(:perform_match! => true)
|
83
|
+
matcher.matches? nil
|
84
|
+
matcher.negative_failure_message.should =~ /Override problem_for_should_not/
|
85
|
+
end
|
58
86
|
end
|
59
87
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,4 +2,9 @@ $: << File.dirname(__FILE__)
|
|
2
2
|
require 'aktion_test'
|
3
3
|
require 'support/autoload'
|
4
4
|
|
5
|
-
AktionTest::SpecHelper.
|
5
|
+
AktionTest::SpecHelper.build do
|
6
|
+
use :AktionTest, :FactoryGirl, :Faker, :RSpec, :Timecop
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.add_group 'Matchers', 'lib/aktion_test/matchers'
|
10
|
+
SimpleCov.add_group 'Modules', 'lib/aktion_test/module'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aktion_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/aktion_test/matchers/file_system/file_contains.rb
|
117
117
|
- lib/aktion_test/matchers/file_system/file_existance.rb
|
118
118
|
- lib/aktion_test/module/aktion_test.rb
|
119
|
+
- lib/aktion_test/module/base.rb
|
119
120
|
- lib/aktion_test/module/factory_girl.rb
|
120
121
|
- lib/aktion_test/module/faker.rb
|
121
122
|
- lib/aktion_test/module/rspec.rb
|
@@ -153,9 +154,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
154
|
- - ! '>='
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
hash: -615248081
|
156
160
|
requirements: []
|
157
161
|
rubyforge_project:
|
158
|
-
rubygems_version: 1.8.
|
162
|
+
rubygems_version: 1.8.25
|
159
163
|
signing_key:
|
160
164
|
specification_version: 3
|
161
165
|
summary: Gems, libs, helpers for test suites.
|