scorched 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'rack/test'
2
+ require_relative '../lib/scorched.rb'
3
+
4
+
5
+ module Scorched
6
+ class SimpleCounter
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env['scorched.simple_counter'] ||= 0
13
+ env['scorched.simple_counter'] += 1
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+
19
+ # We set our target application and rack test environment using let. This ensures tests are isolated, and allows us to
20
+ # easily swap out our target application.
21
+ module GlobalConfig
22
+ extend RSpec::SharedContext
23
+ let(:app) do
24
+ Class.new(Scorched::Controller)
25
+ end
26
+
27
+ let(:rt) do
28
+ Rack::Test::Session.new(app)
29
+ end
30
+
31
+ original_dir = __dir__
32
+ before(:all) do
33
+ Dir.chdir(__dir__)
34
+ end
35
+ after(:all) do
36
+ Dir.chdir(original_dir)
37
+ end
38
+ end
39
+
40
+ RSpec.configure do |c|
41
+ c.alias_example_to :they
42
+ # c.backtrace_clean_patterns = []
43
+ c.include GlobalConfig
44
+ end
@@ -0,0 +1,42 @@
1
+ require_relative './helper.rb'
2
+
3
+ class OptionsA
4
+ include Scorched::Options('colours')
5
+ end
6
+
7
+ class OptionsB < OptionsA
8
+ end
9
+
10
+ class OptionsC < OptionsB
11
+ end
12
+
13
+ module Scorched
14
+ describe Options do
15
+ it "defaults to an empty hash" do
16
+ OptionsA.colours.should be_empty
17
+ end
18
+
19
+ it "can be set to a given hash" do
20
+ my_hash = {car: 'red', house: 'cream'}
21
+ OptionsA.colours.replace my_hash
22
+ OptionsA.colours.should == my_hash
23
+ end
24
+
25
+ it "recursively inherits from parents by default" do
26
+ OptionsB.colours.should == {car: 'red', house: 'cream'}
27
+ OptionsC.colours.should == {car: 'red', house: 'cream'}
28
+ end
29
+
30
+ it "allows values to be overridden without modifying the parent" do
31
+ OptionsB.colours[:car] = 'blue'
32
+ OptionsB.colours[:car].should == 'blue'
33
+ OptionsA.colours[:car].should == 'red'
34
+ end
35
+
36
+ it "provides access to a copy of internal hash" do
37
+ OptionsB.colours.to_hash(false).should == {car: 'blue'}
38
+ OptionsC.colours.to_hash(false).should == {}
39
+ OptionsC.colours.to_hash(false).object_id.should_not == OptionsC.colours.object_id
40
+ end
41
+ end
42
+ end
@@ -0,0 +1 @@
1
+ My static file!
@@ -0,0 +1,2 @@
1
+ # I don't believe Scorched::Request currently needs tests. It's relatively small, and most of it is used and tested by
2
+ # Scorched::Controller and it's unit tests.
@@ -0,0 +1,84 @@
1
+ require_relative './helper.rb'
2
+
3
+ module Scorched
4
+ describe ViewHelpers do
5
+ describe "rendering" do
6
+ before(:each) do
7
+ app.view_config.each { |k,v| app.view_config[k] = nil }
8
+ end
9
+
10
+ it "can render a file, relative to the application root" do
11
+ app.get('/') do
12
+ render(:'views/main.erb').should == "3 for me"
13
+ end
14
+ rt.get('/')
15
+ end
16
+
17
+ it "can render a string" do
18
+ app.get('/') do
19
+ render('<%= 1 + 1 %> for you', engine: :erb).should == "2 for you"
20
+ end
21
+ rt.get('/')
22
+ end
23
+
24
+ it "takes an optional view directory, relative to the application root" do
25
+ app.get('/') do
26
+ render(:'main.erb', dir: 'views').should == "3 for me"
27
+ end
28
+ rt.get('/')
29
+ end
30
+
31
+ it "takes an optional block to be yielded by the view" do
32
+ app.get('/') do
33
+ render(:'views/layout.erb'){ "in the middle" }.should == "(in the middle)"
34
+ end
35
+ rt.get('/')
36
+ end
37
+
38
+ it "renders the given layout" do
39
+ app.get('/') do
40
+ render(:'views/main.erb', layout: :'views/layout.erb').should == "(3 for me)"
41
+ end
42
+ rt.get('/')
43
+ end
44
+
45
+ it "merges options with view config" do
46
+ app.get('/') do
47
+ render(:'main.erb').should == "3 for me"
48
+ end
49
+ app.get('/full_path') do
50
+ render(:'views/main.erb', {layout: :'views/layout.erb', dir: nil}).should == "(3 for me)"
51
+ end
52
+ app.view_config[:dir] = 'views'
53
+ rt.get('/')
54
+ rt.get('/full_path')
55
+ end
56
+
57
+ it "derived template engine overrides specified engine" do
58
+ app.view_config[:dir] = 'views'
59
+ app.view_config[:engine] = :erb
60
+ app.get('/str') do
61
+ render(:'other.str').should == "hello hello"
62
+ end
63
+ app.get('/erb_file') do
64
+ render(:main).should == "3 for me"
65
+ end
66
+ app.get('/erb_string') do
67
+ render('<%= 1 + 1 %> for you').should == "2 for you"
68
+ end
69
+ rt.get('/str')
70
+ rt.get('/erb_file')
71
+ rt.get('/erb_string')
72
+ end
73
+
74
+ it "ignores default layout when called within a view" do
75
+ app.view_config << {:dir => 'views', :layout => :layout, :engine => :erb}
76
+ app.get('/') do
77
+ render :composer
78
+ end
79
+ rt.get('/').body.should == '({1 for none})'
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1 @@
1
+ {<%= render :partial %>}
@@ -0,0 +1 @@
1
+ (<%= yield %>)
@@ -0,0 +1 @@
1
+ <%= 1 + 2 %> for me
@@ -0,0 +1 @@
1
+ #{2.times.map { 'hello' }.join(' ')}
@@ -0,0 +1 @@
1
+ 1 for none
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scorched
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ platform: ruby
6
+ authors:
7
+ - Tom Wardrop
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-accept
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: tilt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.9'
83
+ description: A lightweight Sinatra-inspired web framework for web sites and applications
84
+ of any size.
85
+ email: tom@tomwardrop.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - LICENSE
92
+ - Milestones.md
93
+ - README.md
94
+ - docs/be_creative.md
95
+ - docs/filters.md
96
+ - docs/routing.md
97
+ - docs/sharing_request_state.md
98
+ - examples/media_types.rb
99
+ - examples/media_types.ru
100
+ - lib/scorched.rb
101
+ - lib/scorched/collection.rb
102
+ - lib/scorched/controller.rb
103
+ - lib/scorched/dynamic_delegate.rb
104
+ - lib/scorched/error.rb
105
+ - lib/scorched/options.rb
106
+ - lib/scorched/request.rb
107
+ - lib/scorched/response.rb
108
+ - lib/scorched/static.rb
109
+ - lib/scorched/version.rb
110
+ - lib/scorched/view_helpers.rb
111
+ - scorched.gemspec
112
+ - spec/collection_spec.rb
113
+ - spec/controller_spec.rb
114
+ - spec/helper.rb
115
+ - spec/options_spec.rb
116
+ - spec/public/static.txt
117
+ - spec/request_spec.rb
118
+ - spec/view_helpers_spec.rb
119
+ - spec/views/composer.erb
120
+ - spec/views/layout.erb
121
+ - spec/views/main.erb
122
+ - spec/views/other.str
123
+ - spec/views/partial.erb
124
+ homepage: http://scorchedrb.com
125
+ licenses: []
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options:
129
+ - --line-numbers
130
+ - --inline-source
131
+ - --title
132
+ - Scorched
133
+ - --encoding=UTF-8
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.0.0
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Light-weight, DRY as a desert, web framework for Ruby
152
+ test_files:
153
+ - spec/collection_spec.rb
154
+ - spec/controller_spec.rb
155
+ - spec/options_spec.rb
156
+ - spec/request_spec.rb
157
+ - spec/view_helpers_spec.rb