I am doing a BDD/TDD approach to writing my sinatra application. I would like to add authentication. I currently have a feature file that looks like this:
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
My steps look like this:
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
I am already setting up my app in support/env.rb
:
require 'capybara/cucumber'
Capybara.app = MySintraApp
And my app looks like this:
class MySinatraApp < Sinatra::Base
get '/' do
redirect '/auth/login' #todo: unless logged_in?
haml :index
end
get '/auth/login' do
haml :login
end
end
How do I implement the step to ensure "not logged in"? How would I start to implement the login functionality in a way that would be in a BDD/TDD style?