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 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
@@ -66,8 +66,6 @@ module AktionTest
66
66
  end
67
67
  if missing_files.any?
68
68
  missing_files.map{|f| "#{f} was not found"}.join("\n")
69
- else
70
- "Unknown Problem"
71
69
  end
72
70
  end
73
71
  end
@@ -25,8 +25,6 @@ module AktionTest
25
25
  if File.exists? @subject
26
26
  unless File.directory? @subject
27
27
  "#{@subject} is not a directory."
28
- else
29
- "Unknown"
30
28
  end
31
29
  else
32
30
  "#{@subject} does not exist."
@@ -59,8 +59,6 @@ module AktionTest
59
59
  if File.exists?(@subject)
60
60
  if File.directory?(@subject)
61
61
  "#{@subject} is a directory."
62
- else
63
- "Unknown Problem"
64
62
  end
65
63
  else
66
64
  "#{@subject} does not exist."
@@ -25,8 +25,6 @@ module AktionTest
25
25
  if File.exists?(@subject)
26
26
  if File.directory?(@subject)
27
27
  "#{@subject} is a directory."
28
- else
29
- "Unknown"
30
28
  end
31
29
  else
32
30
  "#{@subject} does not exist."
@@ -1,18 +1,21 @@
1
1
  module AktionTest
2
2
  module Module
3
- module AktionTest
4
- extend ActiveSupport::Concern
5
-
6
- included do |spec_helper|
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
- ::RSpec.configure do |config|
10
- config.include Support::ClassBuilder
11
- config.include Matchers::FileSystem::DirectoryExistance
12
- config.include Matchers::FileSystem::FileExistance
13
- config.include Matchers::FileSystem::DirectoryContains
14
- config.include Matchers::FileSystem::FileContains
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
- module FactoryGirl
4
- extend ActiveSupport::Concern
5
-
6
- included do |spec_helper|
3
+ class FactoryGirl < Base
4
+ def prepare
7
5
  require 'factory_girl'
6
+ end
8
7
 
9
- ::RSpec.configure do |config|
10
- config.include ::FactoryGirl::Syntax::Methods
11
- end
8
+ def configure
9
+ rspec.include ::FactoryGirl::Syntax::Methods
12
10
  end
13
11
  end
14
12
  end
@@ -1,9 +1,7 @@
1
1
  module AktionTest
2
2
  module Module
3
- module Faker
4
- extend ActiveSupport::Concern
5
-
6
- included do |spec_helper|
3
+ class Faker < Base
4
+ def prepare
7
5
  require 'faker'
8
6
  end
9
7
  end
@@ -1,14 +1,10 @@
1
1
  module AktionTest
2
2
  module Module
3
- module RSpec
4
- extend ActiveSupport::Concern
5
-
6
- included do |spec_helper|
7
- ::RSpec.configure do |config|
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
- module Simplecov
4
- require 'simplecov'
5
- ::SimpleCov.start
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
- module Timecop
4
- extend ActiveSupport::Concern
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 'singleton'
1
+ require 'aktion_test/module/base'
2
2
 
3
3
  module AktionTest
4
4
  class SpecHelper
5
- include Singleton
6
-
7
- attr_reader :modules, :options, :scope
5
+ attr_reader :modules, :options
6
+ attr_writer :scope
8
7
 
9
8
  class << self
10
- def load(*names, &block)
11
- if names.any?
12
- instance.load(*names)
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 loaded?(name)
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.each do |name|
46
- unless options.nil? or options.empty?
47
- self.options.merge! name => options
48
- end
49
- load_constant(name)
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
- def within(scope, &block)
54
- self.scope << scope.to_s
55
- yield
56
- self.scope.pop
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
- private
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
- const = name.constantize
65
- self.modules << const
66
- rescue NameError
67
- puts "Unknown module #{name}."
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
- Object.const_set(class_name, constant_class)
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
@@ -1,3 +1,3 @@
1
1
  module AktionTest
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,36 +1,90 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AktionTest::SpecHelper do
4
- subject { described_class.instance }
5
- before { subject.reset }
6
-
7
- its(:modules) { should be_a Array }
8
- its(:options) { should be_a Hash }
9
- its(:scope) { should be_a Array }
10
- its(:scope) { should == %w(AktionTest Module) }
11
-
12
- describe '#within' do
13
- it 'allows a scope to be added' do
14
- subject.within :Test do
15
- subject.scope.should == %w(AktionTest Module Test)
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
- describe '#load' do
22
- it 'initializes the module, adds it to a set of loaded modules, and saves any options' do
23
- subject.scope.pop(2)
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
- Baz.autoload?(:Bar).should_not be_nil
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
- described_class.load :Bar, :test => :option
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.modules.should == [Baz::Bar]
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
@@ -2,13 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  describe AktionTest::Matchers::Base do
4
4
  before :each do
5
- matcher_class = define_class('Matcher', described_class) do
6
- def expectation; "an expectation"; end
7
- def problems_for_should; "\na problem\nanother problem"; end
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
- @matcher = matcher_class.new
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.load :Simplecov, :RSpec, :AktionTest, :Timecop, :FactoryGirl, :Faker
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.2.2
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.24
162
+ rubygems_version: 1.8.25
159
163
  signing_key:
160
164
  specification_version: 3
161
165
  summary: Gems, libs, helpers for test suites.