0

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?

4

1 回答 1

0

我检查用户未登录的一种方法是检查页面是否显示“登录”链接/按钮(以及相关功能)。您可以反过来查看用户是否已登录。例如,用户的姓名是否显示在页面的横幅部分。

这对我来说似乎是最好的方式,因为这是用户确定它的方式,而这完全取决于他们的行为。

于 2012-10-24T09:31:19.353 回答