hobbit-contrib 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'codeclimate-test-reporter'
4
+ CodeClimate::TestReporter.start
5
+
6
+ ENV['RACK_ENV'] ||= 'test'
7
+
8
+ require 'oktobertest'
9
+ require 'rack'
10
+ require 'rack/test'
11
+
12
+ require 'hobbit'
13
+ require 'hobbit/contrib'
14
+
15
+ module Oktobertest
16
+ class Test
17
+ include Rack::Test::Methods
18
+
19
+ def mock_app(&block)
20
+ @app = Class.new(Hobbit::Base, &block).new
21
+ end
22
+
23
+ def app
24
+ @app
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,86 @@
1
+ require 'helper'
2
+
3
+ scope Hobbit::Mote do
4
+ setup do
5
+ mock_app do
6
+ include Hobbit::Mote
7
+
8
+ def views_path
9
+ File.expand_path '../fixtures/mote/views/', __FILE__
10
+ end
11
+
12
+ def name
13
+ 'Hobbit'
14
+ end
15
+
16
+ get('/') { render 'index' }
17
+ get('/partial') { partial 'partial' }
18
+ get('/using-context') { render 'hello' }
19
+ get('/without-layout') { render '_partial', layout: false }
20
+ end
21
+ end
22
+
23
+ scope '#default_layout' do
24
+ test 'defaults to application.mote' do
25
+ assert app.to_app.default_layout == "#{app.to_app.layouts_path}/application.mote"
26
+ end
27
+ end
28
+
29
+ scope '#find_template' do
30
+ test 'returns a template path' do
31
+ assert app.to_app.find_template('index') == "#{app.to_app.views_path}/index.mote"
32
+ end
33
+ end
34
+
35
+ scope '#layouts_path' do
36
+ test 'returns the path to the layouts directory' do
37
+ assert app.to_app.layouts_path == "#{app.to_app.views_path}/layouts"
38
+ end
39
+ end
40
+
41
+ scope '#partial' do
42
+ test 'renders a template without a layout' do
43
+ get '/partial'
44
+ assert last_response.ok?
45
+ assert last_response.body !~ /From application.mote/
46
+ assert last_response.body =~ /Hello World!/
47
+ end
48
+ end
49
+
50
+ scope '#render' do
51
+ test 'renders a template (using a layout)' do
52
+ get '/'
53
+ assert last_response.ok?
54
+ assert last_response.body =~ /From application.mote/
55
+ assert last_response.body =~ /Hello World!/
56
+ end
57
+
58
+ test 'renders a template (not using a layout)' do
59
+ get '/without-layout'
60
+ assert last_response.ok?
61
+ assert last_response.body !~ /From application.mote/
62
+ assert last_response.body =~ /Hello World!/
63
+ end
64
+
65
+ test 'renders a template using the app as context' do
66
+ get '/using-context'
67
+ assert last_response.ok?
68
+ assert last_response.body =~ /From application.mote/
69
+ assert last_response.body =~ /Hello Hobbit!/
70
+ end
71
+ end
72
+
73
+ scope '#views_path' do
74
+ test 'returns the path to the views directory' do
75
+ assert app.to_app.views_path == File.expand_path('../fixtures/mote/views', __FILE__)
76
+ end
77
+
78
+ test 'defaults to "views"' do
79
+ mock_app do
80
+ include Hobbit::Mote
81
+ end
82
+
83
+ assert app.to_app.views_path == 'views'
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,94 @@
1
+ require 'tilt/erubis'
2
+
3
+ require 'helper'
4
+
5
+ scope Hobbit::Render do
6
+ setup do
7
+ mock_app do
8
+ include Hobbit::Render
9
+
10
+ def views_path
11
+ File.expand_path '../fixtures/render/views/', __FILE__
12
+ end
13
+
14
+ def name
15
+ 'Hobbit'
16
+ end
17
+
18
+ get('/') { render 'index' }
19
+ get('/partial') { partial 'partial' }
20
+ get('/using-context') { render 'hello' }
21
+ get('/without-layout') { render '_partial', {}, layout: false }
22
+ end
23
+ end
24
+
25
+ scope '#default_layout' do
26
+ test 'defaults to application.erb' do
27
+ assert app.to_app.default_layout == "#{app.to_app.layouts_path}/application.erb"
28
+ end
29
+ end
30
+
31
+ scope '#find_template' do
32
+ test 'returns a template path' do
33
+ assert app.to_app.find_template('index') == "#{app.to_app.views_path}/index.#{app.to_app.template_engine}"
34
+ end
35
+ end
36
+
37
+ scope '#layouts_path' do
38
+ test 'returns the path to the layouts directory' do
39
+ assert app.to_app.layouts_path == "#{app.to_app.views_path}/layouts"
40
+ end
41
+ end
42
+
43
+ scope '#partial' do
44
+ test 'renders a template without a layout' do
45
+ get '/partial'
46
+ assert last_response.ok?
47
+ assert last_response.body !~ /From application.erb/
48
+ assert last_response.body =~ /Hello World!/
49
+ end
50
+ end
51
+
52
+ scope '#render' do
53
+ test 'renders a template (using a layout)' do
54
+ get '/'
55
+ assert last_response.ok?
56
+ assert last_response.body =~ /From application.erb/
57
+ assert last_response.body =~ /Hello World!/
58
+ end
59
+
60
+ test 'renders a template (not using a layout)' do
61
+ get '/without-layout'
62
+ assert last_response.ok?
63
+ assert last_response.body !~ /From application.erb/
64
+ assert last_response.body =~ /Hello World!/
65
+ end
66
+
67
+ test 'renders a template using the app as context' do
68
+ get '/using-context'
69
+ assert last_response.ok?
70
+ assert last_response.body =~ /From application.erb/
71
+ assert last_response.body =~ /Hello Hobbit!/
72
+ end
73
+ end
74
+
75
+ scope '#template_engine' do
76
+ test 'defaults to erb' do
77
+ assert app.to_app.template_engine == 'erb'
78
+ end
79
+ end
80
+
81
+ scope '#views_path' do
82
+ test 'returns the path to the views directory' do
83
+ assert app.to_app.views_path == File.expand_path('../fixtures/render/views', __FILE__)
84
+ end
85
+
86
+ test 'defaults to "views"' do
87
+ mock_app do
88
+ include Hobbit::Render
89
+ end
90
+
91
+ assert app.to_app.views_path == 'views'
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ scope Hobbit::Session do
4
+ setup do
5
+ mock_app do
6
+ include Hobbit::Session
7
+ use Rack::Session::Cookie, secret: SecureRandom.hex(64)
8
+
9
+ get '/' do
10
+ session[:name] = 'hobbit'
11
+ end
12
+
13
+ get '/name' do
14
+ session[:name]
15
+ end
16
+ end
17
+ end
18
+
19
+ scope '#session' do
20
+ test 'returns a session object' do
21
+ get '/'
22
+ assert last_response.ok?
23
+ assert last_response.body == 'hobbit'
24
+
25
+ get '/name'
26
+ assert last_response.ok?
27
+ assert last_response.body == 'hobbit'
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobbit-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Mac Adden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: erubis
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rack-test
56
+ name: mote
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: oktobertest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,13 +81,13 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: erubis
84
+ name: rack-test
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :runtime
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -95,13 +95,13 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: hobbit
98
+ name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
- type: :runtime
104
+ type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
@@ -109,13 +109,13 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: mote
112
+ name: tilt
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
- type: :runtime
118
+ type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: tilt
126
+ name: hobbit
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -159,22 +159,22 @@ files:
159
159
  - lib/hobbit/mote.rb
160
160
  - lib/hobbit/render.rb
161
161
  - lib/hobbit/session.rb
162
- - spec/environment_spec.rb
163
- - spec/error_handling_and_filter_spec.rb
164
- - spec/error_handling_spec.rb
165
- - spec/filter_spec.rb
166
- - spec/fixtures/mote/views/_partial.mote
167
- - spec/fixtures/mote/views/hello.mote
168
- - spec/fixtures/mote/views/index.mote
169
- - spec/fixtures/mote/views/layouts/application.mote
170
- - spec/fixtures/render/views/_partial.erb
171
- - spec/fixtures/render/views/hello.erb
172
- - spec/fixtures/render/views/index.erb
173
- - spec/fixtures/render/views/layouts/application.erb
174
- - spec/minitest_helper.rb
175
- - spec/mote_spec.rb
176
- - spec/render_spec.rb
177
- - spec/session_spec.rb
162
+ - test/environment_test.rb
163
+ - test/error_handling_and_filter_test.rb
164
+ - test/error_handling_test.rb
165
+ - test/filter_test.rb
166
+ - test/fixtures/mote/views/_partial.mote
167
+ - test/fixtures/mote/views/hello.mote
168
+ - test/fixtures/mote/views/index.mote
169
+ - test/fixtures/mote/views/layouts/application.mote
170
+ - test/fixtures/render/views/_partial.erb
171
+ - test/fixtures/render/views/hello.erb
172
+ - test/fixtures/render/views/index.erb
173
+ - test/fixtures/render/views/layouts/application.erb
174
+ - test/helper.rb
175
+ - test/mote_test.rb
176
+ - test/render_test.rb
177
+ - test/session_test.rb
178
178
  homepage: https://github.com/patriciomacadden/hobbit-contrib
179
179
  licenses:
180
180
  - MIT
@@ -200,19 +200,19 @@ signing_key:
200
200
  specification_version: 4
201
201
  summary: Contributed Hobbit extensions
202
202
  test_files:
203
- - spec/environment_spec.rb
204
- - spec/error_handling_and_filter_spec.rb
205
- - spec/error_handling_spec.rb
206
- - spec/filter_spec.rb
207
- - spec/fixtures/mote/views/_partial.mote
208
- - spec/fixtures/mote/views/hello.mote
209
- - spec/fixtures/mote/views/index.mote
210
- - spec/fixtures/mote/views/layouts/application.mote
211
- - spec/fixtures/render/views/_partial.erb
212
- - spec/fixtures/render/views/hello.erb
213
- - spec/fixtures/render/views/index.erb
214
- - spec/fixtures/render/views/layouts/application.erb
215
- - spec/minitest_helper.rb
216
- - spec/mote_spec.rb
217
- - spec/render_spec.rb
218
- - spec/session_spec.rb
203
+ - test/environment_test.rb
204
+ - test/error_handling_and_filter_test.rb
205
+ - test/error_handling_test.rb
206
+ - test/filter_test.rb
207
+ - test/fixtures/mote/views/_partial.mote
208
+ - test/fixtures/mote/views/hello.mote
209
+ - test/fixtures/mote/views/index.mote
210
+ - test/fixtures/mote/views/layouts/application.mote
211
+ - test/fixtures/render/views/_partial.erb
212
+ - test/fixtures/render/views/hello.erb
213
+ - test/fixtures/render/views/index.erb
214
+ - test/fixtures/render/views/layouts/application.erb
215
+ - test/helper.rb
216
+ - test/mote_test.rb
217
+ - test/render_test.rb
218
+ - test/session_test.rb
@@ -1,105 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Hobbit::Environment do
4
- include Hobbit::Contrib::Mock
5
-
6
- let :app do
7
- mock_app do
8
- include Hobbit::Environment
9
- end
10
- end
11
-
12
- def with_env(environment)
13
- env, ENV['RACK_ENV'] = ENV['RACK_ENV'], environment
14
- yield
15
- ENV['RACK_ENV'] = env
16
- end
17
-
18
- describe '::environment' do
19
- it 'must return the current environment' do
20
- with_env('development') do
21
- app.to_app.class.environment.must_equal :development
22
- end
23
- end
24
- end
25
-
26
- describe '#environment' do
27
- it 'must return the current environment' do
28
- with_env('development') do
29
- app.to_app.environment.must_equal :development
30
- end
31
- end
32
- end
33
-
34
- describe '::development?' do
35
- it "must return true if ENV['RACK_ENV'] = :development" do
36
- with_env('development') do
37
- app.to_app.class.development?.must_equal true
38
- end
39
- end
40
-
41
- it "must return false if ENV['RACK_ENV'] != :development" do
42
- app.to_app.class.development?.must_equal false
43
- end
44
- end
45
-
46
- describe '#development?' do
47
- it "must return true if ENV['RACK_ENV'] = :development" do
48
- with_env('development') do
49
- app.to_app.development?.must_equal true
50
- end
51
- end
52
-
53
- it "must return false if ENV['RACK_ENV'] != :development" do
54
- app.to_app.development?.must_equal false
55
- end
56
- end
57
-
58
- describe '::production?' do
59
- it "must return true if ENV['RACK_ENV'] = :production" do
60
- with_env('production') do
61
- app.to_app.class.production?.must_equal true
62
- end
63
- end
64
-
65
- it "must return false if ENV['RACK_ENV'] != :production" do
66
- app.to_app.class.production?.must_equal false
67
- end
68
- end
69
-
70
- describe '#production?' do
71
- it "must return true if ENV['RACK_ENV'] = :production" do
72
- with_env('production') do
73
- app.to_app.production?.must_equal true
74
- end
75
- end
76
-
77
- it "must return false if ENV['RACK_ENV'] != :production" do
78
- app.to_app.production?.must_equal false
79
- end
80
- end
81
-
82
- describe '::test?' do
83
- it "must return true if ENV['RACK_ENV'] = :test" do
84
- app.to_app.class.test?.must_equal true
85
- end
86
-
87
- it "must return false if ENV['RACK_ENV'] != :test" do
88
- with_env('development') do
89
- app.to_app.class.test?.must_equal false
90
- end
91
- end
92
- end
93
-
94
- describe '#test?' do
95
- it "must return true if ENV['RACK_ENV'] = :test" do
96
- app.to_app.test?.must_equal true
97
- end
98
-
99
- it "must return false if ENV['RACK_ENV'] != :test" do
100
- with_env('development') do
101
- app.to_app.test?.must_equal false
102
- end
103
- end
104
- end
105
- end