thumblemonks-chicago 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +21 -2
- data/chicago.gemspec +2 -1
- data/lib/chicago/helpers.rb +6 -0
- data/lib/chicago/shoulda/sinatra.rb +15 -0
- data/test/helpers_test.rb +49 -0
- data/test/responders_test.rb +1 -1
- data/test/test_helper.rb +3 -0
- metadata +2 -1
data/README.markdown
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Chicago
|
2
2
|
|
3
|
-
|
3
|
+
It's my kind of town!
|
4
|
+
- Sinatra
|
4
5
|
|
5
|
-
|
6
|
+
Yeah, we're real clever. We're also from ["The city in mid-west best city in the whole wide wide world"](http://www.azlyrics.com/lyrics/lupefiasco/gogogadgetflow.html) ... which makes us double the clever.
|
7
|
+
|
8
|
+
## What what?
|
9
|
+
|
10
|
+
### Sinatra runtime app
|
11
|
+
|
12
|
+
In your Sinatra app, do this:
|
13
|
+
|
14
|
+
require 'chicago'
|
15
|
+
|
16
|
+
And you'll get some helpful Sinatra extensions and helpers.
|
17
|
+
|
18
|
+
### Sinatra testing
|
19
|
+
|
20
|
+
If you're using Shoulda in your tests of your Sinatra app, do this:
|
21
|
+
|
22
|
+
require 'chicago/shoulda'
|
23
|
+
|
24
|
+
... and you'll get a bunch of cool Shoulda macros for testing specific Sinatra stuff.
|
data/chicago.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "chicago"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.2"
|
4
4
|
s.date = "2008-12-05"
|
5
5
|
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
|
6
6
|
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.test_files = %w[
|
31
31
|
test/application_test.rb
|
32
32
|
test/responders_test.rb
|
33
|
+
test/helpers_test.rb
|
33
34
|
test/test_helper.rb
|
34
35
|
]
|
35
36
|
end
|
data/lib/chicago/helpers.rb
CHANGED
@@ -13,6 +13,12 @@ module Thumblemonks
|
|
13
13
|
options_str = hash_to_attributes(defaults.merge(options))
|
14
14
|
%Q[<link #{options_str}/>]
|
15
15
|
end
|
16
|
+
|
17
|
+
def javascript_include(name, options={})
|
18
|
+
defaults = {:src => "/javascripts/#{name}.js", :type => "text/javascript"}
|
19
|
+
options_str = hash_to_attributes(defaults.merge(options))
|
20
|
+
%Q[<script #{options_str}></script>]
|
21
|
+
end
|
16
22
|
private
|
17
23
|
def hash_to_attributes(options)
|
18
24
|
options.map {|k,v| "#{k}=\"#{v}\""}.join(' ')
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module Thumblemonks
|
4
5
|
module Shoulda
|
@@ -30,6 +31,20 @@ module Thumblemonks
|
|
30
31
|
assert_response_body json
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
# Will invoke a helper method in the EventContext and set the result of
|
36
|
+
# output to @response.body.
|
37
|
+
#
|
38
|
+
# NOTE: This will probably break right now if you need access to specific
|
39
|
+
# event context methods or Sinatra.app options in your helper.
|
40
|
+
def should_invoke_helper(name, *args, &assert_block)
|
41
|
+
should "invoke helper #{name} with #{args.inspect}" do
|
42
|
+
@response = OpenStruct.new(:body => nil)
|
43
|
+
event_context = ::Sinatra::EventContext.new(nil, @response, nil)
|
44
|
+
@response.body = event_context.send(name, *args)
|
45
|
+
self.instance_eval(&assert_block)
|
46
|
+
end
|
47
|
+
end
|
33
48
|
end # Macros
|
34
49
|
|
35
50
|
module Helpers
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class HelpersTest < Test::Unit::TestCase
|
4
|
+
context "including stylesheets" do
|
5
|
+
should_invoke_helper(:stylesheet_include, 'foo') do
|
6
|
+
assert_match %r[^<link( \w+=".+"){4}/>$], @response.body
|
7
|
+
assert_match %r[href="/stylesheets/foo\.css"], @response.body
|
8
|
+
assert_match %r[media="screen"], @response.body
|
9
|
+
assert_match %r[rel="stylesheet"], @response.body
|
10
|
+
assert_match %r[type="text/css"], @response.body
|
11
|
+
end
|
12
|
+
|
13
|
+
should_invoke_helper(:stylesheet_include, 'bar', :media => 'print', :baz => 'boo') do
|
14
|
+
assert_match %r[^<link( \w+=".+"){5}/>$], @response.body
|
15
|
+
assert_match %r[href="/stylesheets/bar\.css"], @response.body
|
16
|
+
assert_match %r[media="print"], @response.body
|
17
|
+
assert_match %r[rel="stylesheet"], @response.body
|
18
|
+
assert_match %r[type="text/css"], @response.body
|
19
|
+
assert_match %r[baz="boo"], @response.body
|
20
|
+
end
|
21
|
+
end # including stylesheets
|
22
|
+
|
23
|
+
context "including javascript" do
|
24
|
+
should_invoke_helper(:javascript_include, 'foo') do
|
25
|
+
assert_match %r[^<script( \w+=".+"){2}></script>$], @response.body
|
26
|
+
assert_match %r[src="/javascripts/foo\.js"], @response.body
|
27
|
+
assert_match %r[type="text/javascript"], @response.body
|
28
|
+
end
|
29
|
+
|
30
|
+
should_invoke_helper(:javascript_include, 'foo', :type => "text/blarg", :gus => "nice") do
|
31
|
+
assert_match %r[^<script( \w+=".+"){3}></script>$], @response.body
|
32
|
+
assert_match %r[src="/javascripts/foo\.js"], @response.body
|
33
|
+
assert_match %r[type="text/blarg"], @response.body
|
34
|
+
assert_match %r[gus="nice"], @response.body
|
35
|
+
end
|
36
|
+
end # including javascript
|
37
|
+
|
38
|
+
context "using an anchor" do
|
39
|
+
should_invoke_helper(:anchor, 'foo', '/bar') do
|
40
|
+
assert_equal %Q[<a href="/bar">foo</a>], @response.body
|
41
|
+
end
|
42
|
+
|
43
|
+
should_invoke_helper(:anchor, 'foo bear', '/bar/ler', :title => "gus is nice") do
|
44
|
+
assert_match %r[^<a( \w+=".+"){2}>foo bear</a>$], @response.body
|
45
|
+
assert_match %r[href="/bar/ler"], @response.body
|
46
|
+
assert_match %r[title="gus is nice"], @response.body
|
47
|
+
end
|
48
|
+
end # using an anchor
|
49
|
+
end
|
data/test/responders_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thumblemonks-chicago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Knowlden
|
@@ -67,4 +67,5 @@ summary: Sinatra runtime and testing extensions used commonly by Thumblemonks
|
|
67
67
|
test_files:
|
68
68
|
- test/application_test.rb
|
69
69
|
- test/responders_test.rb
|
70
|
+
- test/helpers_test.rb
|
70
71
|
- test/test_helper.rb
|