Class: MiniTest::Unit::TestCase
- Inherits:
-
Object
- Object
- MiniTest::Unit::TestCase
- Includes:
- Rack::Test::Methods
- Defined in:
- lib/padrino-cms/test/helper.rb
Overview
class Class
# Allow assertions in request context
include MiniTest::Assertions
end
Instance Method Summary collapse
- #app ⇒ Object
-
#assert_file_exists(file_path) ⇒ Object
Assert_file_exists(‘/tmp/app’).
-
#assert_match_in_file(pattern, file) ⇒ Object
Asserts that a file matches the pattern.
-
#assert_no_file_exists(file_path) ⇒ Object
Assert_no_file_exists(‘/tmp/app’).
- #assert_no_match_in_file(pattern, file) ⇒ Object
-
#generate(name, *params) ⇒ Object
generate(:admin_app, “-r=#@apptmp/sample_project”).
-
#method_missing(name, *args, &block) ⇒ Object
Delegate other missing methods to response.
-
#mock_app(base = Padrino::Application, &block) ⇒ Object
Sets up a Sinatra::Base subclass defined with the block given.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Delegate other missing methods to response.
70 71 72 73 74 75 76 |
# File 'lib/padrino-cms/test/helper.rb', line 70 def method_missing(name, *args, &block) if response && response.respond_to?(name) response.send(name, *args, &block) else super(name, *args, &block) end end |
Instance Method Details
#app ⇒ Object
41 42 43 |
# File 'lib/padrino-cms/test/helper.rb', line 41 def app Rack::Lint.new(@app) end |
#assert_file_exists(file_path) ⇒ Object
Assert_file_exists(‘/tmp/app’)
51 52 53 |
# File 'lib/padrino-cms/test/helper.rb', line 51 def assert_file_exists(file_path) assert File.exist?(file_path), "File at path '#{file_path}' does not exist!" end |
#assert_match_in_file(pattern, file) ⇒ Object
Asserts that a file matches the pattern
61 62 63 |
# File 'lib/padrino-cms/test/helper.rb', line 61 def assert_match_in_file(pattern, file) File.exist?(file) ? assert_match(pattern, File.read(file)) : assert_file_exists(file) end |
#assert_no_file_exists(file_path) ⇒ Object
Assert_no_file_exists(‘/tmp/app’)
56 57 58 |
# File 'lib/padrino-cms/test/helper.rb', line 56 def assert_no_file_exists(file_path) assert !File.exist?(file_path), "File should not exist at path '#{file_path}' but was found!" end |
#assert_no_match_in_file(pattern, file) ⇒ Object
65 66 67 |
# File 'lib/padrino-cms/test/helper.rb', line 65 def assert_no_match_in_file(pattern, file) File.exists?(file) ? assert_no_match(pattern, File.read(file)) : assert_file_exists(file) end |
#generate(name, *params) ⇒ Object
generate(:admin_app, “-r=#@apptmp/sample_project”)
46 47 48 |
# File 'lib/padrino-cms/test/helper.rb', line 46 def generate(name, *params) "Padrino::Generators::#{name.to_s.camelize}".constantize.start(params) end |
#mock_app(base = Padrino::Application, &block) ⇒ Object
Sets up a Sinatra::Base subclass defined with the block given. Used in setup or individual spec methods to establish the application.
35 36 37 38 39 |
# File 'lib/padrino-cms/test/helper.rb', line 35 def mock_app(base=Padrino::Application, &block) @app = Sinatra.new(base, &block) @app.send :include, MiniTest::Assertions @app.register Padrino::Helpers end |