super-pro-kit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/slim-5.2.1/CHANGES +496 -0
- data/slim-5.2.1/Gemfile +43 -0
- data/slim-5.2.1/LICENSE +21 -0
- data/slim-5.2.1/README.jp.md +1276 -0
- data/slim-5.2.1/README.md +1313 -0
- data/slim-5.2.1/Rakefile +80 -0
- data/slim-5.2.1/bin/slimrb +6 -0
- data/slim-5.2.1/doc/include.md +20 -0
- data/slim-5.2.1/doc/jp/include.md +20 -0
- data/slim-5.2.1/doc/jp/logic_less.md +137 -0
- data/slim-5.2.1/doc/jp/smart.md +102 -0
- data/slim-5.2.1/doc/jp/translator.md +28 -0
- data/slim-5.2.1/doc/logic_less.md +137 -0
- data/slim-5.2.1/doc/smart.md +120 -0
- data/slim-5.2.1/doc/translator.md +28 -0
- data/slim-5.2.1/lib/slim/code_attributes.rb +68 -0
- data/slim-5.2.1/lib/slim/command.rb +122 -0
- data/slim-5.2.1/lib/slim/controls.rb +61 -0
- data/slim-5.2.1/lib/slim/do_inserter.rb +34 -0
- data/slim-5.2.1/lib/slim/embedded.rb +248 -0
- data/slim-5.2.1/lib/slim/end_inserter.rb +63 -0
- data/slim-5.2.1/lib/slim/engine.rb +42 -0
- data/slim-5.2.1/lib/slim/erb_converter.rb +15 -0
- data/slim-5.2.1/lib/slim/filter.rb +31 -0
- data/slim-5.2.1/lib/slim/grammar.rb +24 -0
- data/slim-5.2.1/lib/slim/include.rb +58 -0
- data/slim-5.2.1/lib/slim/interpolation.rb +36 -0
- data/slim-5.2.1/lib/slim/logic_less/context.rb +126 -0
- data/slim-5.2.1/lib/slim/logic_less/filter.rb +81 -0
- data/slim-5.2.1/lib/slim/logic_less.rb +6 -0
- data/slim-5.2.1/lib/slim/parser.rb +535 -0
- data/slim-5.2.1/lib/slim/railtie.rb +19 -0
- data/slim-5.2.1/lib/slim/smart/escaper.rb +42 -0
- data/slim-5.2.1/lib/slim/smart/filter.rb +97 -0
- data/slim-5.2.1/lib/slim/smart/parser.rb +35 -0
- data/slim-5.2.1/lib/slim/smart.rb +9 -0
- data/slim-5.2.1/lib/slim/splat/builder.rb +115 -0
- data/slim-5.2.1/lib/slim/splat/filter.rb +93 -0
- data/slim-5.2.1/lib/slim/template.rb +6 -0
- data/slim-5.2.1/lib/slim/translator.rb +119 -0
- data/slim-5.2.1/lib/slim/version.rb +6 -0
- data/slim-5.2.1/lib/slim.rb +16 -0
- data/slim-5.2.1/slim.gemspec +33 -0
- data/slim-5.2.1/test/core/helper.rb +201 -0
- data/slim-5.2.1/test/core/test_code_blocks.rb +194 -0
- data/slim-5.2.1/test/core/test_code_escaping.rb +162 -0
- data/slim-5.2.1/test/core/test_code_evaluation.rb +181 -0
- data/slim-5.2.1/test/core/test_code_output.rb +168 -0
- data/slim-5.2.1/test/core/test_code_structure.rb +203 -0
- data/slim-5.2.1/test/core/test_commands.rb +219 -0
- data/slim-5.2.1/test/core/test_embedded_engines.rb +247 -0
- data/slim-5.2.1/test/core/test_encoding.rb +28 -0
- data/slim-5.2.1/test/core/test_erb_converter.rb +65 -0
- data/slim-5.2.1/test/core/test_html_attributes.rb +276 -0
- data/slim-5.2.1/test/core/test_html_escaping.rb +65 -0
- data/slim-5.2.1/test/core/test_html_structure.rb +599 -0
- data/slim-5.2.1/test/core/test_parser_errors.rb +148 -0
- data/slim-5.2.1/test/core/test_pretty.rb +163 -0
- data/slim-5.2.1/test/core/test_ruby_errors.rb +200 -0
- data/slim-5.2.1/test/core/test_slim_template.rb +78 -0
- data/slim-5.2.1/test/core/test_splat_prefix_option.rb +155 -0
- data/slim-5.2.1/test/core/test_tabs.rb +169 -0
- data/slim-5.2.1/test/core/test_text_interpolation.rb +79 -0
- data/slim-5.2.1/test/core/test_thread_options.rb +18 -0
- data/slim-5.2.1/test/core/test_unicode.rb +15 -0
- data/slim-5.2.1/test/include/files/recursive.slim +1 -0
- data/slim-5.2.1/test/include/files/slimfile.slim +3 -0
- data/slim-5.2.1/test/include/files/subdir/test.slim +1 -0
- data/slim-5.2.1/test/include/files/textfile +1 -0
- data/slim-5.2.1/test/include/test_include.rb +24 -0
- data/slim-5.2.1/test/literate/TESTS.md +1323 -0
- data/slim-5.2.1/test/literate/helper.rb +15 -0
- data/slim-5.2.1/test/literate/run.rb +92 -0
- data/slim-5.2.1/test/logic_less/test_logic_less.rb +330 -0
- data/slim-5.2.1/test/rails/Rakefile +7 -0
- data/slim-5.2.1/test/rails/app/assets/config/manifest.js +1 -0
- data/slim-5.2.1/test/rails/app/controllers/application_controller.rb +2 -0
- data/slim-5.2.1/test/rails/app/controllers/entries_controller.rb +5 -0
- data/slim-5.2.1/test/rails/app/controllers/slim_controller.rb +46 -0
- data/slim-5.2.1/test/rails/app/helpers/application_helper.rb +5 -0
- data/slim-5.2.1/test/rails/app/models/entry.rb +16 -0
- data/slim-5.2.1/test/rails/app/views/entries/edit.html.slim +3 -0
- data/slim-5.2.1/test/rails/app/views/layouts/application.html+testvariant.slim +10 -0
- data/slim-5.2.1/test/rails/app/views/layouts/application.html.slim +10 -0
- data/slim-5.2.1/test/rails/app/views/slim/_partial.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/attributes.html.slim +3 -0
- data/slim-5.2.1/test/rails/app/views/slim/content_for.html.slim +7 -0
- data/slim-5.2.1/test/rails/app/views/slim/erb.html.erb +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/form_for.html.slim +2 -0
- data/slim-5.2.1/test/rails/app/views/slim/helper.html.slim +4 -0
- data/slim-5.2.1/test/rails/app/views/slim/integers.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/no_layout.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/normal.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/partial.html.slim +2 -0
- data/slim-5.2.1/test/rails/app/views/slim/splat.html.slim +2 -0
- data/slim-5.2.1/test/rails/app/views/slim/splat_with_delimiter.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/thread_options.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/variables.html.slim +1 -0
- data/slim-5.2.1/test/rails/app/views/slim/xml.slim +1 -0
- data/slim-5.2.1/test/rails/config/application.rb +44 -0
- data/slim-5.2.1/test/rails/config/boot.rb +10 -0
- data/slim-5.2.1/test/rails/config/environment.rb +5 -0
- data/slim-5.2.1/test/rails/config/environments/test.rb +34 -0
- data/slim-5.2.1/test/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/slim-5.2.1/test/rails/config/initializers/inflections.rb +10 -0
- data/slim-5.2.1/test/rails/config/initializers/mime_types.rb +5 -0
- data/slim-5.2.1/test/rails/config/initializers/session_store.rb +8 -0
- data/slim-5.2.1/test/rails/config/locales/en.yml +5 -0
- data/slim-5.2.1/test/rails/config/routes.rb +60 -0
- data/slim-5.2.1/test/rails/config.ru +4 -0
- data/slim-5.2.1/test/rails/script/rails +6 -0
- data/slim-5.2.1/test/rails/test/helper.rb +34 -0
- data/slim-5.2.1/test/rails/test/test_slim.rb +102 -0
- data/slim-5.2.1/test/sinatra/contest.rb +91 -0
- data/slim-5.2.1/test/sinatra/helper.rb +143 -0
- data/slim-5.2.1/test/sinatra/test_core.rb +91 -0
- data/slim-5.2.1/test/sinatra/test_include.rb +16 -0
- data/slim-5.2.1/test/sinatra/views/embed_include_js.slim +8 -0
- data/slim-5.2.1/test/sinatra/views/embed_js.slim +11 -0
- data/slim-5.2.1/test/sinatra/views/footer.slim +1 -0
- data/slim-5.2.1/test/sinatra/views/hello.slim +1 -0
- data/slim-5.2.1/test/sinatra/views/layout2.slim +3 -0
- data/slim-5.2.1/test/smart/test_smart_text.rb +294 -0
- data/slim-5.2.1/test/translator/test_translator.rb +76 -0
- data/super-pro-kit.gemspec +11 -0
- metadata +165 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Dummy::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
+
|
|
4
|
+
# The test environment is used exclusively to run your application's
|
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
|
8
|
+
config.cache_classes = true
|
|
9
|
+
|
|
10
|
+
# Show full error reports and disable caching
|
|
11
|
+
config.consider_all_requests_local = true
|
|
12
|
+
config.action_controller.perform_caching = false
|
|
13
|
+
|
|
14
|
+
# Raise exceptions instead of rendering exception templates
|
|
15
|
+
config.action_dispatch.show_exceptions = false
|
|
16
|
+
|
|
17
|
+
# Disable request forgery protection in test environment
|
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
|
19
|
+
|
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
|
22
|
+
# ActionMailer::Base.deliveries array.
|
|
23
|
+
#config.action_mailer.delivery_method = :test
|
|
24
|
+
|
|
25
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
|
26
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
|
27
|
+
# like if you have constraints or database-specific column types
|
|
28
|
+
# config.active_record.schema_format = :sql
|
|
29
|
+
|
|
30
|
+
# Print deprecation notices to the stderr
|
|
31
|
+
config.active_support.deprecation = :stderr
|
|
32
|
+
|
|
33
|
+
config.eager_load = false
|
|
34
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
|
5
|
+
|
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Add new inflection rules using the following format
|
|
4
|
+
# (all these examples are active by default):
|
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
|
8
|
+
# inflect.irregular 'person', 'people'
|
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
|
10
|
+
# end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
|
4
|
+
|
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
|
6
|
+
# which shouldn't be used to store highly confidential information
|
|
7
|
+
# (create the session table with "rails generate session_migration")
|
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Dummy::Application.routes.draw do
|
|
2
|
+
# The priority is based upon order of creation:
|
|
3
|
+
# first created -> highest priority.
|
|
4
|
+
|
|
5
|
+
resources :entries
|
|
6
|
+
|
|
7
|
+
# Sample of regular route:
|
|
8
|
+
# match 'products/:id' => 'catalog#view'
|
|
9
|
+
# Keep in mind you can assign values other than :controller and :action
|
|
10
|
+
|
|
11
|
+
# Sample of named route:
|
|
12
|
+
# match 'products/:id/purchase' => 'catalog#purchase', as: :purchase
|
|
13
|
+
# This route can be invoked with purchase_url(id: product.id)
|
|
14
|
+
|
|
15
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
|
16
|
+
# resources :products
|
|
17
|
+
|
|
18
|
+
# Sample resource route with options:
|
|
19
|
+
# resources :products do
|
|
20
|
+
# member do
|
|
21
|
+
# get 'short'
|
|
22
|
+
# post 'toggle'
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# collection do
|
|
26
|
+
# get 'sold'
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
|
|
30
|
+
# Sample resource route with sub-resources:
|
|
31
|
+
# resources :products do
|
|
32
|
+
# resources :comments, :sales
|
|
33
|
+
# resource :seller
|
|
34
|
+
# end
|
|
35
|
+
|
|
36
|
+
# Sample resource route with more complex sub-resources
|
|
37
|
+
# resources :products do
|
|
38
|
+
# resources :comments
|
|
39
|
+
# resources :sales do
|
|
40
|
+
# get 'recent', on: :collection
|
|
41
|
+
# end
|
|
42
|
+
# end
|
|
43
|
+
|
|
44
|
+
# Sample resource route within a namespace:
|
|
45
|
+
# namespace :admin do
|
|
46
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
|
47
|
+
# # (app/controllers/admin/products_controller.rb)
|
|
48
|
+
# resources :products
|
|
49
|
+
# end
|
|
50
|
+
|
|
51
|
+
# You can have the root of your site routed with "root"
|
|
52
|
+
# just remember to delete public/index.html.
|
|
53
|
+
# root to: "welcome#index"
|
|
54
|
+
|
|
55
|
+
# See how all your routes lay out with "rake routes"
|
|
56
|
+
|
|
57
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
|
58
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
|
59
|
+
get ':controller(/:action(/:id(.:format)))'
|
|
60
|
+
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
require 'rails/commands'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Configure Rails Envinronment
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
|
|
4
|
+
require File.expand_path("../../config/environment.rb", __FILE__)
|
|
5
|
+
require "rails/test_help"
|
|
6
|
+
require "nokogiri"
|
|
7
|
+
|
|
8
|
+
require 'rails-controller-testing'
|
|
9
|
+
Rails::Controller::Testing.install
|
|
10
|
+
|
|
11
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
12
|
+
|
|
13
|
+
class ActionDispatch::IntegrationTest
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
def assert_xpath(xpath, message="Unable to find '#{xpath}' in response body.")
|
|
18
|
+
assert_response :success, "Response type is not :success (code 200..299)."
|
|
19
|
+
|
|
20
|
+
body = @response.body
|
|
21
|
+
assert !body.empty?, "No response body found."
|
|
22
|
+
|
|
23
|
+
doc = Nokogiri::HTML(body) rescue nil
|
|
24
|
+
assert_not_nil doc, "Cannot parse response body."
|
|
25
|
+
|
|
26
|
+
assert doc.xpath(xpath).size >= 1, message
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def assert_html(expected, options = {})
|
|
30
|
+
expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{options[:heading]}<div class=\"content\">#{expected}</div></body></html>" unless options[:skip_layout]
|
|
31
|
+
assert_equal expected, @response.body
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
class TestSlim < ActionDispatch::IntegrationTest
|
|
4
|
+
test "normal view" do
|
|
5
|
+
get "/slim/normal"
|
|
6
|
+
assert_response :success
|
|
7
|
+
assert_template "slim/normal"
|
|
8
|
+
assert_template "layouts/application"
|
|
9
|
+
assert_html "<h1>Hello Slim!</h1>"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "variant" do
|
|
13
|
+
get "/slim/variant"
|
|
14
|
+
assert_response :success
|
|
15
|
+
assert_template "slim/normal"
|
|
16
|
+
assert_template "layouts/application"
|
|
17
|
+
assert_equal @response.body, "<!DOCTYPE html><html><head><title>Variant</title></head><body><div class=\"content\"><h1>Hello Slim!</h1></div></body></html>"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "xml view" do
|
|
21
|
+
get "/slim/xml"
|
|
22
|
+
assert_response :success
|
|
23
|
+
assert_template "slim/xml"
|
|
24
|
+
assert_template "layouts/application"
|
|
25
|
+
assert_html "<h1>Hello Slim!</h1>"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "helper" do
|
|
29
|
+
get "/slim/helper"
|
|
30
|
+
assert_response :success
|
|
31
|
+
assert_template "slim/helper"
|
|
32
|
+
assert_template "layouts/application"
|
|
33
|
+
assert_html "<p><h1>Hello User</h1></p>"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test "normal erb view" do
|
|
37
|
+
get "/slim/erb"
|
|
38
|
+
assert_html "<h1>Hello Erb!</h1>"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test "view without a layout" do
|
|
42
|
+
get "/slim/no_layout"
|
|
43
|
+
assert_template "slim/no_layout"
|
|
44
|
+
assert_html "<h1>Hello Slim without a layout!</h1>", skip_layout: true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
test "view with variables" do
|
|
48
|
+
get "/slim/variables"
|
|
49
|
+
assert_html "<h1>Hello Slim with variables!</h1>"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test "partial view" do
|
|
53
|
+
get "/slim/partial"
|
|
54
|
+
assert_html "<h1>Hello Slim!</h1><p>With a partial!</p>"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# TODO Reenable streaming test
|
|
58
|
+
# test "streaming" do
|
|
59
|
+
# get "/slim/streaming"
|
|
60
|
+
# output = "2f\r\n<!DOCTYPE html><html><head><title>Dummy</title>\r\nd\r\n</head><body>\r\n17\r\nHeading set from a view\r\n15\r\n<div class=\"content\">\r\n53\r\n<p>Page content</p><h1><p>Hello Streaming!</p></h1><h2><p>Hello Streaming!</p></h2>\r\n14\r\n</div></body></html>\r\n0\r\n\r\n"
|
|
61
|
+
# assert_equal output, @response.body
|
|
62
|
+
# end
|
|
63
|
+
|
|
64
|
+
test "render integers" do
|
|
65
|
+
get "/slim/integers"
|
|
66
|
+
assert_html "<p>1337</p>"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
test "render thread_options" do
|
|
70
|
+
get "/slim/thread_options", params: { attr: 'role'}
|
|
71
|
+
assert_html '<p role="empty">Test</p>'
|
|
72
|
+
get "/slim/thread_options", params: { attr: 'id'} # Overwriting doesn't work because of caching
|
|
73
|
+
assert_html '<p role="empty">Test</p>'
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
test "content_for" do
|
|
77
|
+
get "/slim/content_for"
|
|
78
|
+
assert_html "<p>Page content</p><h1><p>Hello Slim!</p></h1><h2><p>Hello Slim!</p></h2>", heading: 'Heading set from a view'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test "form_for" do
|
|
82
|
+
get "/entries/edit/1"
|
|
83
|
+
assert_match %r{action="/entries"}, @response.body
|
|
84
|
+
assert_match %r{<label><b>Name</b></label>}, @response.body
|
|
85
|
+
assert_xpath '//input[@id="entry_name" and @name="entry[name]" and @type="text"]'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
test "attributes" do
|
|
89
|
+
get "/slim/attributes"
|
|
90
|
+
assert_html "<div class=\"static a-b\"></div>"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
test "splat" do
|
|
94
|
+
get "/slim/splat"
|
|
95
|
+
assert_html "<div id=\"splat\"><splat>Hello</splat></div>"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
test "splat with delimiter" do
|
|
99
|
+
get "/slim/splat_with_delimiter"
|
|
100
|
+
assert_html "<div class=\"cute nice\">Hello</div>"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
|
11
|
+
# all copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
# THE SOFTWARE.
|
|
20
|
+
require "rubygems"
|
|
21
|
+
require "minitest/autorun"
|
|
22
|
+
|
|
23
|
+
# Contest adds +teardown+, +test+ and +context+ as class methods, and the
|
|
24
|
+
# instance methods +setup+ and +teardown+ now iterate on the corresponding
|
|
25
|
+
# blocks. Note that all setup and teardown blocks must be defined with the
|
|
26
|
+
# block syntax. Adding setup or teardown instance methods defeats the purpose
|
|
27
|
+
# of this library.
|
|
28
|
+
class Minitest::Test
|
|
29
|
+
def self.setup(&block) setup_blocks << block end
|
|
30
|
+
def self.teardown(&block) teardown_blocks << block end
|
|
31
|
+
def self.setup_blocks() @setup_blocks ||= [] end
|
|
32
|
+
def self.teardown_blocks() @teardown_blocks ||= [] end
|
|
33
|
+
|
|
34
|
+
def setup_blocks(base = self.class)
|
|
35
|
+
setup_blocks base.superclass if base.superclass.respond_to? :setup_blocks
|
|
36
|
+
base.setup_blocks.each do |block|
|
|
37
|
+
instance_eval(&block)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def teardown_blocks(base = self.class)
|
|
42
|
+
teardown_blocks base.superclass if base.superclass.respond_to? :teardown_blocks
|
|
43
|
+
base.teardown_blocks.each do |block|
|
|
44
|
+
instance_eval(&block)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
alias setup setup_blocks
|
|
49
|
+
alias teardown teardown_blocks
|
|
50
|
+
|
|
51
|
+
def self.context(*name, &block)
|
|
52
|
+
subclass = Class.new(self)
|
|
53
|
+
remove_tests(subclass)
|
|
54
|
+
subclass.class_eval(&block) if block_given?
|
|
55
|
+
const_set(context_name(name.join(" ")), subclass)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.test(name, &block)
|
|
59
|
+
define_method(test_name(name), &block)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class << self
|
|
63
|
+
alias_method :should, :test
|
|
64
|
+
alias_method :describe, :context
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def self.context_name(name)
|
|
70
|
+
# "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
|
|
71
|
+
name = "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}"
|
|
72
|
+
name.tr(" ", "_").to_sym
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.test_name(name)
|
|
76
|
+
name = "test_#{sanitize_name(name).gsub(/\s+/,'_')}_0"
|
|
77
|
+
name = name.succ while method_defined? name
|
|
78
|
+
name.to_sym
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.sanitize_name(name)
|
|
82
|
+
# name.gsub(/\W+/, ' ').strip
|
|
83
|
+
name.gsub(/\W+/, ' ')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def self.remove_tests(subclass)
|
|
87
|
+
subclass.public_instance_methods.grep(/^test_/).each do |meth|
|
|
88
|
+
subclass.send(:undef_method, meth.to_sym)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
if ENV['COVERAGE']
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
SimpleCov.start do
|
|
4
|
+
add_filter '/test/'
|
|
5
|
+
add_group 'sinatra-contrib', 'sinatra-contrib'
|
|
6
|
+
add_group 'rack-protection', 'rack-protection'
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
ENV['APP_ENV'] = 'test'
|
|
11
|
+
RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
|
|
12
|
+
|
|
13
|
+
require 'rack'
|
|
14
|
+
|
|
15
|
+
testdir = File.dirname(__FILE__)
|
|
16
|
+
$LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
|
|
17
|
+
|
|
18
|
+
libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
|
|
19
|
+
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
|
20
|
+
|
|
21
|
+
require 'minitest'
|
|
22
|
+
require 'contest'
|
|
23
|
+
require 'rack/test'
|
|
24
|
+
require 'sinatra'
|
|
25
|
+
require 'sinatra/base'
|
|
26
|
+
|
|
27
|
+
class Sinatra::Base
|
|
28
|
+
include Minitest::Assertions
|
|
29
|
+
# Allow assertions in request context
|
|
30
|
+
def assertions
|
|
31
|
+
@assertions ||= 0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
attr_writer :assertions
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Rack::Builder
|
|
38
|
+
def include?(middleware)
|
|
39
|
+
@ins.any? { |m| middleware === m }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Sinatra::Base.set :environment, :test
|
|
44
|
+
|
|
45
|
+
class Minitest::Test
|
|
46
|
+
include Rack::Test::Methods
|
|
47
|
+
|
|
48
|
+
class << self
|
|
49
|
+
alias_method :it, :test
|
|
50
|
+
alias_method :section, :context
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.example(desc = nil, &block)
|
|
54
|
+
@example_count = 0 unless instance_variable_defined? :@example_count
|
|
55
|
+
@example_count += 1
|
|
56
|
+
it(desc || "Example #{@example_count}", &block)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
alias_method :response, :last_response
|
|
60
|
+
|
|
61
|
+
setup do
|
|
62
|
+
Sinatra::Base.set :environment, :test
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
|
66
|
+
# given. Used in setup or individual spec methods to establish
|
|
67
|
+
# the application.
|
|
68
|
+
def mock_app(base=Sinatra::Base, &block)
|
|
69
|
+
@app = Sinatra.new(base, &block)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def app
|
|
73
|
+
Rack::Lint.new(@app)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def slim_app(&block)
|
|
77
|
+
mock_app do
|
|
78
|
+
set :views, File.dirname(__FILE__) + '/views'
|
|
79
|
+
get('/', &block)
|
|
80
|
+
end
|
|
81
|
+
get '/'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def body
|
|
85
|
+
response.body.to_s
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def assert_body(value)
|
|
89
|
+
if value.respond_to? :to_str
|
|
90
|
+
assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
|
|
91
|
+
else
|
|
92
|
+
assert_match value, body
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def assert_status(expected)
|
|
97
|
+
assert_equal Integer(expected), Integer(status)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def assert_like(a,b)
|
|
101
|
+
pattern = /id=['"][^"']*["']|\s+/
|
|
102
|
+
assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def assert_include(str, substr)
|
|
106
|
+
assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def options(uri, params = {}, env = {}, &block)
|
|
110
|
+
request(uri, env.merge(:method => "OPTIONS", :params => params), &block)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def patch(uri, params = {}, env = {}, &block)
|
|
114
|
+
request(uri, env.merge(:method => "PATCH", :params => params), &block)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def link(uri, params = {}, env = {}, &block)
|
|
118
|
+
request(uri, env.merge(:method => "LINK", :params => params), &block)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def unlink(uri, params = {}, env = {}, &block)
|
|
122
|
+
request(uri, env.merge(:method => "UNLINK", :params => params), &block)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Delegate other missing methods to response.
|
|
126
|
+
def method_missing(name, *args, &block)
|
|
127
|
+
if response && response.respond_to?(name)
|
|
128
|
+
response.send(name, *args, &block)
|
|
129
|
+
else
|
|
130
|
+
super
|
|
131
|
+
end
|
|
132
|
+
rescue Rack::Test::Error
|
|
133
|
+
super
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Do not output warnings for the duration of the block.
|
|
137
|
+
def silence_warnings
|
|
138
|
+
$VERBOSE, v = nil, $VERBOSE
|
|
139
|
+
yield
|
|
140
|
+
ensure
|
|
141
|
+
$VERBOSE = v
|
|
142
|
+
end
|
|
143
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require_relative 'helper.rb'
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
class SlimTest < Minitest::Test
|
|
5
|
+
it 'renders inline slim strings' do
|
|
6
|
+
slim_app { slim "h1 Hiya\n" }
|
|
7
|
+
assert ok?
|
|
8
|
+
assert_equal "<h1>Hiya</h1>", body
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'renders .slim files in views path' do
|
|
12
|
+
slim_app { slim :hello }
|
|
13
|
+
assert ok?
|
|
14
|
+
assert_equal "<h1>Hello From Slim</h1>", body
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "renders with inline layouts" do
|
|
18
|
+
mock_app do
|
|
19
|
+
layout { %(h1\n | THIS. IS. \n == yield.upcase ) }
|
|
20
|
+
get('/') { slim 'em Sparta' }
|
|
21
|
+
end
|
|
22
|
+
get '/'
|
|
23
|
+
assert ok?
|
|
24
|
+
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "renders with file layouts" do
|
|
28
|
+
slim_app { slim('| Hello World', :layout => :layout2) }
|
|
29
|
+
assert ok?
|
|
30
|
+
assert_equal "<h1>Slim Layout!</h1><p>Hello World</p>", body
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "raises error if template not found" do
|
|
34
|
+
mock_app { get('/') { slim(:no_such_template) } }
|
|
35
|
+
assert_raises(Errno::ENOENT) { get('/') }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
HTML4_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
|
|
39
|
+
|
|
40
|
+
it "passes slim options to the slim engine" do
|
|
41
|
+
mock_app { get('/') { slim("x foo='bar'", :attr_quote => "'") }}
|
|
42
|
+
get '/'
|
|
43
|
+
assert ok?
|
|
44
|
+
assert_body "<x foo='bar'></x>"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "passes default slim options to the slim engine" do
|
|
48
|
+
mock_app do
|
|
49
|
+
set :slim, :attr_quote => "'"
|
|
50
|
+
get('/') { slim("x foo='bar'") }
|
|
51
|
+
end
|
|
52
|
+
get '/'
|
|
53
|
+
assert ok?
|
|
54
|
+
assert_body "<x foo='bar'></x>"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "merges the default slim options with the overrides and passes them to the slim engine" do
|
|
58
|
+
mock_app do
|
|
59
|
+
set :slim, :attr_quote => "'"
|
|
60
|
+
get('/') { slim("x foo='bar'") }
|
|
61
|
+
get('/other') { slim("x foo='bar'", :attr_quote => '"') }
|
|
62
|
+
end
|
|
63
|
+
get '/'
|
|
64
|
+
assert ok?
|
|
65
|
+
assert_body "<x foo='bar'></x>"
|
|
66
|
+
get '/other'
|
|
67
|
+
assert ok?
|
|
68
|
+
assert_body '<x foo="bar"></x>'
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "can render truly nested layouts by accepting a layout and a block with the contents" do
|
|
72
|
+
mock_app do
|
|
73
|
+
template(:main_outer_layout) { "h1 Title\n== yield" }
|
|
74
|
+
template(:an_inner_layout) { "h2 Subtitle\n== yield" }
|
|
75
|
+
template(:a_page) { "p Contents." }
|
|
76
|
+
get('/') do
|
|
77
|
+
slim :main_outer_layout, :layout => false do
|
|
78
|
+
slim :an_inner_layout do
|
|
79
|
+
slim :a_page
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
get '/'
|
|
85
|
+
assert ok?
|
|
86
|
+
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
rescue LoadError
|
|
90
|
+
warn "#{$!}: skipping slim tests"
|
|
91
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'slim/include'
|
|
2
|
+
|
|
3
|
+
require_relative 'helper.rb'
|
|
4
|
+
|
|
5
|
+
begin
|
|
6
|
+
class SlimTest < Minitest::Test
|
|
7
|
+
it 'renders .slim files includes with js embed' do
|
|
8
|
+
slim_app { slim :embed_include_js }
|
|
9
|
+
assert ok?
|
|
10
|
+
assert_equal "<!DOCTYPE html><html><head><title>Slim Examples</title><script>alert('Slim supports embedded javascript!')</script></head><body><footer>Slim</footer></body></html>", body
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
rescue LoadError
|
|
15
|
+
warn "#{$!}: skipping slim tests"
|
|
16
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
footer Slim
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
h1 Hello From Slim
|