0
我正在做一個BDD/TDD方法來編寫我的sinatra應用程序。我想添加身份驗證。我現在有一個看起來像這樣的特性文件:如何使用黃瓜在Sinatra應用程序中測試身份驗證?
Scenario: Unauthenticated redirects to login page
Given I am not logged in
When I go to the homepage
Then I should be redirected to the login page
我的步驟是這樣的:
Given /^I am not logged in$/ do
# not sure how to ensure this
end
When /^I go to the homepage$/ do
visit '/'
end
Then /^I should be redirected to the login page$/ do
current_path.should == '/auth/login'
end
我已經在support/env.rb
設置我的應用程序:
require 'capybara/cucumber'
Capybara.app = MySintraApp
和我應用看起來像這樣:
class MySinatraApp < Sinatra::Base
get '/' do
redirect '/auth/login' #todo: unless logged_in?
haml :index
end
get '/auth/login' do
haml :login
end
end
如何實施確保「未登錄」的步驟?我將如何開始以BDD/TDD風格的方式實現登錄功能?