Class: Sinatra::Spec
- Inherits:
-
MiniTest::Spec
- Object
- MiniTest::Spec
- Sinatra::Spec
- Includes:
- Rack::Test::Methods
- Defined in:
- lib/sinatra/spec.rb
Overview
This spec is a base for specs that describe Sinatra apps. It mixes in Rack::Test::Methods and provides an #app method that resolves to the app, so long as the app is used as the spec’s desc
, e.g.:
describe MyApp do
describe "GET /" do
it "should respond ok" do
get "/"
assert last_response.ok?
end
end
end
Class Method Summary collapse
-
.app_class ⇒ Object
Returns an anonymous subclass of this spec’s app class.
-
.is_base?(desc) ⇒ Boolean
Returns
true
if the givendesc
is a class that is a descendant of Sinatra::Base, for which Sinatra::Spec may be used.
Instance Method Summary collapse
-
#app ⇒ Object
Returns an instance of the #app_class fronted by its middleware.
-
#app_class ⇒ Object
Returns the subclass of Sinatra::Base this spec describes.
Class Method Details
.app_class ⇒ Object
Returns an anonymous subclass of this spec’s app class. The class is subclassed so that each spec may modify its own copy of the app without affecting others.
32 33 34 |
# File 'lib/sinatra/spec.rb', line 32 def self.app_class @app_class ||= Class.new(is_base?(desc) ? desc : superclass.app_class) end |
.is_base?(desc) ⇒ Boolean
Returns true
if the given desc
is a class that is a descendant of Sinatra::Base, for which Sinatra::Spec may be used.
23 24 25 26 27 |
# File 'lib/sinatra/spec.rb', line 23 def self.is_base?(desc) Sinatra::Base > desc rescue TypeError false end |
Instance Method Details
#app ⇒ Object
Returns an instance of the #app_class fronted by its middleware. Used by Rack::Test::Methods to call the app.
43 44 45 |
# File 'lib/sinatra/spec.rb', line 43 def app app_class.new end |
#app_class ⇒ Object
Returns the subclass of Sinatra::Base this spec describes.
37 38 39 |
# File 'lib/sinatra/spec.rb', line 37 def app_class self.class.app_class end |