Created
April 20, 2011 01:41
-
-
Save achiurizo/930156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') | |
| context "PagesController" do | |
| context "GET :index" do | |
| setup { get '/pages' } | |
| # These two are the same | |
| asserts_body.matches %r{Something} # My custom helper | |
| asserts("that it shows something") { last_response.body }.matches %r{Something} | |
| # Negative assertions | |
| denies_body.matches %r{Another} | |
| denies("that it shows another") { last_response.body }.matches %r{another} | |
| asserts_status.equals 200 # also my custom helper | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb') | |
| context "PagesController" do | |
| app SubApp.tap { |app| } | |
| context "GET :tos" do | |
| setup { get '/tos' } | |
| # These two are the same | |
| asserts_body.matches %r{Something} # My custom helper | |
| asserts("that it shows something") { last_response.body }.matches %r{Something} | |
| asserts_status.equals 200 # also my custom helper | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PADRINO_ENV = 'test' unless defined?(PADRINO_ENV) | |
| require File.expand_path(File.dirname(__FILE__) + "/../config/boot") | |
| require 'riot/rr' | |
| Riot.pretty_dots | |
| # Specify your app using the #app helper inside a context. | |
| # Takes either an app class or a block argument. | |
| # app { Padrino.application } | |
| # | |
| class Riot::Situation | |
| include Rack::Test::Methods | |
| ## | |
| # You can handle all padrino applications using instead: | |
| # Padrino.application | |
| def app | |
| @app || Padrino.application | |
| end | |
| end | |
| class Riot::Context | |
| # Set the Rack app which is to be tested. | |
| # | |
| # context "MyApp" do | |
| # app { [200, {}, "Hello!"] } | |
| # setup { get '/' } | |
| # asserts(:status).equals(200) | |
| # end | |
| def app(app=nil, &block) | |
| setup { @app = (app || block.call) } | |
| end | |
| # Returns assertion for last_response body | |
| # asserts_body.matches %r{Hi} | |
| def asserts_body(description="body") | |
| asserts(description) { last_response.body } | |
| end | |
| # Returns negation for last_response body | |
| # denies_body.matches %r{Hi} | |
| def denies_body(description="body") | |
| denies(description) { last_response.body } | |
| end | |
| # Returns assertion for last_response status | |
| # asserts_status.matches 'ok' | |
| def asserts_status(description="status") | |
| asserts(description) { last_response.status } | |
| end | |
| # Returns negation for last_response status | |
| # denies_status.matches 'ok' | |
| def denies_status(description="status") | |
| denies(description) { last_response.status } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment