aktion_test 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.2.1
2
+ * Improve spec helper
3
+ * Add FactoryGirl, Faker and Timecop
4
+
1
5
  # v0.2.0
2
6
  * Build out a better base matcher class
3
7
  * Implement a SpecHelper loading interface
@@ -0,0 +1,11 @@
1
+ module AktionTest
2
+ module Module
3
+ module FactoryGirl
4
+ extend ActiveSupport::Concern
5
+
6
+ included do |spec_helper|
7
+ require 'factory_girl'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module AktionTest
2
+ module Module
3
+ module Faker
4
+ extend ActiveSupport::Concern
5
+
6
+ included do |spec_helper|
7
+ require 'faker'
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,11 @@
1
+ module AktionTest
2
+ module Module
3
+ module Timecop
4
+ extend ActiveSupport::Concern
5
+
6
+ included do |spec_helper|
7
+ require 'timecop'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,27 +4,40 @@ module AktionTest
4
4
  class SpecHelper
5
5
  include Singleton
6
6
 
7
- attr_accessor :modules
7
+ attr_reader :modules, :options, :scope
8
8
 
9
9
  class << self
10
- include ActiveSupport::Callbacks
11
- define_callbacks :load
10
+ def load(*names, &block)
11
+ options = names.extract_options!
12
12
 
13
- def load(*modules)
14
- load_constants(modules)
13
+ if names.any?
14
+ load_constants(names)
15
15
 
16
- instance.modules.each do |mod|
17
- include mod
16
+ unless options.nil? || options.empty?
17
+ names.each do |name|
18
+ instance.options.merge! name => options
19
+ end
20
+ end
21
+
22
+ instance.modules.each do |mod|
23
+ include mod
24
+ end
18
25
  end
19
26
 
20
- puts "Loaded #{modules.map(&:to_s).join(', ')}"
27
+ self.instance_eval(&block) if block_given?
28
+ end
29
+
30
+ def within(scope, &block)
31
+ instance.scope << scope.to_s
32
+ yield
33
+ instance.scope.pop
21
34
  end
22
35
 
23
36
  private
24
37
 
25
38
  def load_constants(modules)
26
39
  modules.each do |mod|
27
- module_name = "AktionTest::Module::#{mod}"
40
+ module_name = "#{instance.scope.join('::')}::#{mod}"
28
41
  begin
29
42
  module_const = module_name.constantize
30
43
  instance.modules << module_const
@@ -36,7 +49,17 @@ module AktionTest
36
49
  end
37
50
 
38
51
  def initialize
52
+ reset
53
+ end
54
+
55
+ def reset
39
56
  @modules = []
57
+ @options = {}
58
+ @scope = %w(AktionTest Module)
59
+ end
60
+
61
+ def loaded?(name)
62
+ eval "defined? AktionTest::Module::#{name}"
40
63
  end
41
64
  end
42
65
  end
@@ -1,3 +1,3 @@
1
1
  module AktionTest
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/aktion_test.rb CHANGED
@@ -11,8 +11,11 @@ module AktionTest
11
11
  extend ActiveSupport::Autoload
12
12
 
13
13
  autoload :AktionTest
14
+ autoload :FactoryGirl
15
+ autoload :Faker
14
16
  autoload :RSpec, 'aktion_test/module/rspec'
15
17
  autoload :Simplecov
18
+ autoload :Timecop
16
19
  end
17
20
 
18
21
  module Matchers
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
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
+ described_class.within :Test do
15
+ subject.scope.should == %w(AktionTest Module Test)
16
+ end
17
+ subject.scope.should == %w(AktionTest Module)
18
+ end
19
+ end
20
+
21
+ describe '#load' do
22
+ before do
23
+ subject.scope.pop(2)
24
+ subject.scope << 'Baz'
25
+ end
26
+
27
+ it 'initializes the module' do
28
+ Baz.autoload?(:Bar).should == 'support/test_module'
29
+ described_class.load :Bar
30
+ Baz.autoload?(:Bar).should be_nil
31
+ end
32
+
33
+ it 'adds the module to a set of loaded modules' do
34
+ described_class.load :Bar
35
+ subject.modules.should == [Baz::Bar]
36
+ end
37
+
38
+ it 'saves options for the module loaded' do
39
+ described_class.load :Bar, :test => :option
40
+ subject.options.should have_key(:Bar)
41
+ subject.options[:Bar].should == {:test => :option}
42
+ end
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ $: << File.dirname(__FILE__)
1
2
  require 'aktion_test'
3
+ require 'support/autoload'
2
4
 
3
- AktionTest::SpecHelper.load :Simplecov, :RSpec, :AktionTest
5
+ AktionTest::SpecHelper.load :Simplecov, :RSpec, :AktionTest, :Timecop, :FactoryGirl, :Faker
@@ -0,0 +1,3 @@
1
+ module Baz
2
+ autoload :Bar, 'support/test_module'
3
+ end
@@ -0,0 +1,4 @@
1
+ module Baz
2
+ module Bar
3
+ end
4
+ end
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.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -116,18 +116,24 @@ 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/factory_girl.rb
120
+ - lib/aktion_test/module/faker.rb
119
121
  - lib/aktion_test/module/rspec.rb
120
122
  - lib/aktion_test/module/simplecov.rb
123
+ - lib/aktion_test/module/timecop.rb
121
124
  - lib/aktion_test/spec_helper.rb
122
125
  - lib/aktion_test/support/class_builder.rb
123
126
  - lib/aktion_test/version.rb
124
127
  - spec/aktion_test/class_builder_spec.rb
128
+ - spec/aktion_test/spec_helper_spec.rb
125
129
  - spec/matchers/base_spec.rb
126
130
  - spec/matchers/directory_contains_spec.rb
127
131
  - spec/matchers/directory_existance_spec.rb
128
132
  - spec/matchers/file_contains_spec.rb
129
133
  - spec/matchers/file_existance_spec.rb
130
134
  - spec/spec_helper.rb
135
+ - spec/support/autoload.rb
136
+ - spec/support/test_module.rb
131
137
  homepage: http://aktionlab.com
132
138
  licenses:
133
139
  - MIT
@@ -149,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
155
  version: '0'
150
156
  segments:
151
157
  - 0
152
- hash: -214091085
158
+ hash: 847893389
153
159
  requirements: []
154
160
  rubyforge_project:
155
161
  rubygems_version: 1.8.24
@@ -158,9 +164,12 @@ specification_version: 3
158
164
  summary: Gems, libs, helpers for test suites.
159
165
  test_files:
160
166
  - spec/aktion_test/class_builder_spec.rb
167
+ - spec/aktion_test/spec_helper_spec.rb
161
168
  - spec/matchers/base_spec.rb
162
169
  - spec/matchers/directory_contains_spec.rb
163
170
  - spec/matchers/directory_existance_spec.rb
164
171
  - spec/matchers/file_contains_spec.rb
165
172
  - spec/matchers/file_existance_spec.rb
166
173
  - spec/spec_helper.rb
174
+ - spec/support/autoload.rb
175
+ - spec/support/test_module.rb