-3

我有这个代码:https ://github.com/roelof1967/tamara 但是当我做黄瓜时,它会失败并显示此错误消息:https ://gist.github.com/4008123

谁能向我解释我的代码有什么问题?

罗洛夫

编辑1:失败的代码:

class Output  
def messages    
   @messages ||= []  
end    
def puts(message)    
    messages << message  
end    
def output    
   @output ||= Output.new  
end
end

When /^he logs in$/ do   
   visit("/users/sign_in")  
   fill_in('Email', :with => @user.email)  
   fill_in('Password', :with => @user.password)  
   click_button('Sign in')
end

Then /^he should see "(.*?)"$/ do |message|  
  @output.messages.should include (message)
end

这是错误消息:

undefined method `[]' for nil:NilClass NoMethodError)      
./features/step_definitions/login_steps.rb:6:in `/^he logs in$/'          
features/login.feature:5:in `When he logs in'
4

1 回答 1

0

为您的解决方案执行此操作:

第一步:创建家庭控制器

class HomeController < ApplicationController
  def index
  end
end

第 2 步home在其中创建文件夹view并创建index.html.erb文件,您的内容看起来像一个例子

<% if current_user.present? %>
  <h1> <%= link_to "Sign Out", destroy_user_session_path, :method => :delete %> </h1>
<% else %>
  <h1> <%= link_to "Sign Up", "/users/sign_up" %> |<%= link_to "Sign In", user_session_path %> </h1>
<% end %> 

第 3 步:现在你的login.feature文件看起来像

Feature: login and authecation

Scenario: log in as existing user
  Given a user "roelof" exists
  When he logs in
  Then he should see "Signed in successfully."
  And he should see "Sign Out"

Scenario: log in with bad password
  Given a user "Aslak" exists
  When he logs in with a bad password
  Then he should not see "Welcome, Aslak"
  And he should see "Login failed"

现在第 4 步,运行cucumber

您的方案“以现有用户身份登录”将通过。

于 2012-11-06T11:26:50.137 回答