dicer 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ class TestContext < Dicer::Context
2
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Testable do
4
+ extend_to { User.new }
5
+
6
+ it { should respond_to(:testable?) }
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe BookStorePurchaseContext do
4
+ controller do
5
+ def hello; nil; end
6
+ end
7
+
8
+ it { should be_a BookStorePurchaseContext }
9
+
10
+ its(:controller) { should respond_to :hello }
11
+ its(:controller) { should == controller }
12
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestContext do
4
+ end
data/lib/dicer/railtie.rb CHANGED
@@ -19,6 +19,10 @@ module Dicer
19
19
  if Dicer.config.auto_supply && !defined?(ActiveRecord)
20
20
  puts "Dicer's auto_supply option is supporting ActiveRecord only"
21
21
  end
22
+
23
+ unless Rails.env.production?
24
+ require 'dicer/rspec' if defined?(RSpec)
25
+ end
22
26
  end
23
27
 
24
28
  # Paths
@@ -0,0 +1,27 @@
1
+ module Dicer
2
+ module RSpec
3
+ module BehabiorExampleGroup
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ subject do
8
+ extend_to.as(described_class)
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def extend_to(&block)
14
+ let(:extend_to, &block)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ ::RSpec.configure do |config|
21
+ config.include(
22
+ RSpec::BehabiorExampleGroup,
23
+ :example_group => { :file_path => %r{spec/behaviors} },
24
+ :type => :behavior
25
+ )
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ require 'action_controller/test_case'
2
+
3
+ module Dicer
4
+ module RSpec
5
+ module ContextExampleGroup
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ metadata[:type] = :context
10
+
11
+ controller
12
+
13
+ let(:controller) do
14
+ (
15
+ example.metadata[:controller] ||
16
+ ::ApplicationController
17
+ ).new
18
+ end
19
+
20
+ before do
21
+ controller.request =
22
+ example.metadata[:request] ||
23
+ ::ActionController::TestRequest.new
24
+
25
+ Dicer::Context.current_controller = controller
26
+ end
27
+
28
+ subject(:context) { described_class.new }
29
+ end
30
+
31
+ module ClassMethods
32
+ def controller(base_class = ::ApplicationController, &block)
33
+ metadata[:controller] = Class.new(base_class) do
34
+ def self.name; 'AnonymouseController'; end
35
+ end
36
+ metadata[:controller].class_eval(&block) if block
37
+ end
38
+
39
+ def request(env = nil, &block)
40
+ test_request = ::ActionController::TestRequest.new(env)
41
+ test_request.instance_eval(&block) if block
42
+
43
+ metadata[:request] = test_request
44
+ end
45
+ end
46
+
47
+ def request; controller.request; end
48
+ end
49
+ end
50
+
51
+ ::RSpec.configure do |config|
52
+ config.include(
53
+ RSpec::ContextExampleGroup,
54
+ :example_group => { :file_path => %r{spec/contexts} },
55
+ :type => :context
56
+ )
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ require 'dicer/rspec/context_example_group'
2
+ require 'dicer/rspec/behavior_example_group'
data/lib/dicer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dicer
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -15,6 +15,8 @@ module Rails
15
15
  )
16
16
  )
17
17
  end
18
+
19
+ hook_for :test_framework
18
20
  end
19
21
  end
20
22
  end
@@ -22,6 +22,8 @@ module Rails
22
22
  )
23
23
  end
24
24
 
25
+ hook_for :test_framework
26
+
25
27
  private
26
28
  def parent_class_name
27
29
  options[:parent] || defined?(ApplicationContext) ?
@@ -0,0 +1,16 @@
1
+ module Rspec
2
+ class BehaviorGenerator < ::Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_spec_file
6
+ template(
7
+ 'behavior_spec.rb',
8
+ File.join(
9
+ 'spec/behaviors',
10
+ class_path,
11
+ "#{singular_name}_behavior_spec.rb"
12
+ )
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Rspec
2
+ class ContextGenerator < ::Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def create_spec_file
6
+ template(
7
+ 'context_spec.rb',
8
+ File.join(
9
+ 'spec/contexts',
10
+ class_path,
11
+ "#{singular_name}_context_spec.rb"
12
+ )
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ # extend_to { User.new }
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Context do
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-12 00:00:00.000000000 Z
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -119,6 +119,7 @@ files:
119
119
  - examples/rails-3.2/app/behaviors/testable.rb
120
120
  - examples/rails-3.2/app/contexts/application_context.rb
121
121
  - examples/rails-3.2/app/contexts/book_store_purchase_context.rb
122
+ - examples/rails-3.2/app/contexts/test_context.rb
122
123
  - examples/rails-3.2/app/controllers/application_controller.rb
123
124
  - examples/rails-3.2/app/controllers/book_store_controller.rb
124
125
  - examples/rails-3.2/app/helpers/application_helper.rb
@@ -159,6 +160,9 @@ files:
159
160
  - examples/rails-3.2/public/index.html
160
161
  - examples/rails-3.2/public/robots.txt
161
162
  - examples/rails-3.2/script/rails
163
+ - examples/rails-3.2/spec/behaviors/testable_spec.rb
164
+ - examples/rails-3.2/spec/contexts/book_store_purchase_context_spec.rb
165
+ - examples/rails-3.2/spec/contexts/test_context_spec.rb
162
166
  - examples/rails-3.2/spec/controllers/book_store_controller_spec.rb
163
167
  - examples/rails-3.2/spec/factories/book_purchases.rb
164
168
  - examples/rails-3.2/spec/factories/books.rb
@@ -185,11 +189,18 @@ files:
185
189
  - lib/dicer/railtie/active_record.rb
186
190
  - lib/dicer/railtie/context.rb
187
191
  - lib/dicer/railtie/contextable.rb
192
+ - lib/dicer/rspec.rb
193
+ - lib/dicer/rspec/behavior_example_group.rb
194
+ - lib/dicer/rspec/context_example_group.rb
188
195
  - lib/dicer/version.rb
189
196
  - lib/generators/behavior/behavior_generator.rb
190
197
  - lib/generators/behavior/template/behavior.rb
191
198
  - lib/generators/context/context_generator.rb
192
199
  - lib/generators/context/template/context.rb
200
+ - lib/generators/rspec/behavior_generator.rb
201
+ - lib/generators/rspec/context_generator.rb
202
+ - lib/generators/rspec/templates/behavior_spec.rb
203
+ - lib/generators/rspec/templates/context_spec.rb
193
204
  - resource/dice.png
194
205
  - resource/dicer_logo.png
195
206
  - spec/dicer/behavior_spec.rb
@@ -219,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
230
  version: '0'
220
231
  segments:
221
232
  - 0
222
- hash: -253257026553297279
233
+ hash: 2972979481225296162
223
234
  required_rubygems_version: !ruby/object:Gem::Requirement
224
235
  none: false
225
236
  requirements:
@@ -228,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
239
  version: '0'
229
240
  segments:
230
241
  - 0
231
- hash: -253257026553297279
242
+ hash: 2972979481225296162
232
243
  requirements: []
233
244
  rubyforge_project:
234
245
  rubygems_version: 1.8.23