2013-08-31 2 views
0

먼저 그 레일 3 행동에 따라, 그래서 내가 가진 모든 것들을 입력하고 모든 사람이 나를 도울 수 있고 거기에 중요한 파일을 추가해야합니다 오류가 발생했습니다 질문하시기 바랍니다 ... 또한 어쩌면 질문의 제목은 어쩌면 좋을지 모르지만 나는 어떤 제목을 내가 오이 질문에 제공해야할지 모르겠다.오이 테스트 이상한 방법으로 연기

저자가 편집 및 삭제 링크를 숨기려하고있어 서명되지 않은 사용자와 로그인 한 사용자가 관리자라는 것을 제외하고는 볼 수 없습니다.

그는 1.4.3 버전과 오이 버전 1.0.6을 사용하고 있습니다. 특히 7 장 7.3에 나와 있습니다.

지금 책의 단계는 우리가 편집을 숨기기 위해 오이 테스트를 wirte하고 링크를 삭제 것이라고 말했다 그것은 그것의 코드였다 hidden_links.feature 다음

Scenario: Edit project link is hidden for non-signed-in users 
    Given I am on the homepage 
    When I follow "TextMate 2" 
    Then I should not see the "Edit Project" link 

Scenario: Edit project link is hidden for signed-in user 
    Given I am signed in as "[email protected]" 
    When I follow "TextMate 2" 
    Then I should not see the "Edit Project" link 

Scenario: Edit project link is shown to admin 
    Given I am signed in as "[email protected]" 
    When I follow "TextMate 2" 
    Then I should see the "Edit Proeject" link 

Scenario: Delete project link is hidden for non-signed-in users 
    Given I am on the homepage 
    When I follow "TextMate 2" 
    Then I should not see the "Delete Project" link 

Scenario: Delete project link is hidden for signed-in users 
    Given I am signed in as "[email protected]" 
    When I follow "TextMate 2" 
    Then I should not see the "Delete Project" link 

Scenario: Delete project link is shown to admins 
    Given I am signed in as "[email protected]" 
    When I follow "TextMate 2" 
    Then I should see the "Delete Project" link 

내가 가지고 테스트를 실행하려고 할 때 기능 누락에 대한 문제 (시험 후 통과하고 책에 있지만은 GitHub의 푸시해야하지만 나를 위해 그것을 통과하지) 그래서 난 내 코드의 상단에이를 추가 한 : 지금 때

Feature: Hidden Links 
    In order to clean up the user experience 
    As the system 
    I want to hide links from users who can't act on them 

테스트를 실행하려고하는데이 오류가 발생합니다 :

➜ ticketee git:(master) ✗ bin/cucumber features/hidden_links.feature 
Rack::File headers parameter replaces cache_control after Rack 1.5. 
Using the default profile... 
Feature: Hidden Links 
    In order to clean up the user experience 
    As the system 
    I want to hide links from users who can't act on them 

    Scenario: Edit project link is hidden for non-signed-in users # features/hidden_links.feature:6 
    Given I am on the homepage         # features/step_definitions/web_steps.rb:44 
    When I follow "TextMate 2"         # features/step_definitions/web_steps.rb:56 
     Unable to find link "TextMate 2" (Capybara::ElementNotFound) 
     ./features/step_definitions/web_steps.rb:57:in `/^(?:|I)follow "([^"]*)"$/' 
     features/hidden_links.feature:8:in `When I follow "TextMate 2"' 
    Then I should not see the "Edit Project" link    # features/hidden_links.feature:9 
     Undefined step: "I should not see the "Edit Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:9:in `Then I should not see the "Edit Project" link' 

    Scenario: Edit project link is hidden for signed-in user # features/hidden_links.feature:11 
    Given I am signed in as "[email protected]"   # features/hidden_links.feature:12 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:12:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"        # features/step_definitions/web_steps.rb:56 
    Then I should not see the "Edit Project" link   # features/hidden_links.feature:14 
     Undefined step: "I should not see the "Edit Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:14:in `Then I should not see the "Edit Project" link' 

    Scenario: Edit project link is shown to admin # features/hidden_links.feature:16 
    Given I am signed in as "[email protected]" # features/hidden_links.feature:17 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:17:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"     # features/step_definitions/web_steps.rb:56 
    Then I should see the "Edit Proeject" link # features/hidden_links.feature:19 
     Undefined step: "I should see the "Edit Proeject" link" (Cucumber::Undefined) 
     features/hidden_links.feature:19:in `Then I should see the "Edit Proeject" link' 

    Scenario: Delete project link is hidden for non-signed-in users # features/hidden_links.feature:21 
    Given I am on the homepage         # features/step_definitions/web_steps.rb:44 
    When I follow "TextMate 2"         # features/step_definitions/web_steps.rb:56 
     Unable to find link "TextMate 2" (Capybara::ElementNotFound) 
     ./features/step_definitions/web_steps.rb:57:in `/^(?:|I)follow "([^"]*)"$/' 
     features/hidden_links.feature:23:in `When I follow "TextMate 2"' 
    Then I should not see the "Delete Project" link    # features/hidden_links.feature:24 
     Undefined step: "I should not see the "Delete Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:24:in `Then I should not see the "Delete Project" link' 

    Scenario: Delete project link is hidden for signed-in users # features/hidden_links.feature:26 
    Given I am signed in as "[email protected]"    # features/hidden_links.feature:27 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:27:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"        # features/step_definitions/web_steps.rb:56 
    Then I should not see the "Delete Project" link   # features/hidden_links.feature:29 
     Undefined step: "I should not see the "Delete Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:29:in `Then I should not see the "Delete Project" link' 

    Scenario: Delete project link is shown to admins # features/hidden_links.feature:31 
    Given I am signed in as "[email protected]" # features/hidden_links.feature:32 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:32:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"      # features/step_definitions/web_steps.rb:56 
    Then I should see the "Delete Project" link # features/hidden_links.feature:34 
     Undefined step: "I should see the "Delete Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:34:in `Then I should see the "Delete Project" link' 

Failing Scenarios: 
cucumber features/hidden_links.feature:6 # Scenario: Edit project link is hidden for non-signed-in users 
cucumber features/hidden_links.feature:21 # Scenario: Delete project link is hidden for non-signed-in users 

6 scenarios (2 failed, 4 undefined) 
18 steps (2 failed, 4 skipped, 10 undefined, 2 passed) 
0m0.187s 

You can implement step definitions for undefined steps with these snippets: 

Then(/^I should not see the "(.*?)" link$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

Given(/^I am signed in as "(.*?)"$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

Then(/^I should see the "(.*?)" link$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

은 그 때 나는 내 테스트를 통과 할 수 있도록 노력하기 위해 내 코드에 이것을 추가 : 다음

Background: 
    Given there are the following users: 
    | email    | password | admin | 
    | [email protected] | password | false | 
    | [email protected] | password | true | 
    And there is a project called "TextMate 2" 

내가 테스트를 실행하고이 오류를 가지고 :

➜ ticketee git:(master) ✗ bin/cucumber features/hidden_links.feature 
Rack::File headers parameter replaces cache_control after Rack 1.5. 
Using the default profile... 
Feature: Hidden Links 
    In order to clean up the user experience 
    As the system 
    I want to hide links from users who can't act on them 

    Background:         # features/hidden_links.feature:6 
    Given there are the following users:  # features/step_definitions/user_steps.rb:1 
     | email    | password | admin | 
     | [email protected] | password | false | 
     | [email protected] | password | true | 
    And there is a project called "TextMate 2" # features/step_definitions/project_steps.rb:1 

    Scenario: Edit project link is hidden for non-signed-in users # features/hidden_links.feature:13 
    Given I am on the homepage         # features/step_definitions/web_steps.rb:44 
    When I follow "TextMate 2"         # features/step_definitions/web_steps.rb:56 
     undefined method `admins_only' for #<#<Class:0x9c16994>:0x9d134b4> (ActionView::Template::Error) 
     ./app/views/projects/show.html.erb:3:in `_app_views_projects_show_html_erb___713092924_82350660' 

     ./features/step_definitions/web_steps.rb:57:in `/^(?:|I)follow "([^"]*)"$/' 
     features/hidden_links.feature:15:in `When I follow "TextMate 2"' 
    Then I should not see the "Edit Project" link    # features/hidden_links.feature:16 
     Undefined step: "I should not see the "Edit Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:16:in `Then I should not see the "Edit Project" link' 

    Scenario: Edit project link is hidden for signed-in user # features/hidden_links.feature:18 
    Given I am signed in as "[email protected]"   # features/hidden_links.feature:19 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:19:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"        # features/step_definitions/web_steps.rb:56 
    Then I should not see the "Edit Project" link   # features/hidden_links.feature:21 
     Undefined step: "I should not see the "Edit Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:21:in `Then I should not see the "Edit Project" link' 

    Scenario: Edit project link is shown to admin # features/hidden_links.feature:23 
    Given I am signed in as "[email protected]" # features/hidden_links.feature:24 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:24:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"     # features/step_definitions/web_steps.rb:56 
    Then I should see the "Edit Proeject" link # features/hidden_links.feature:26 
     Undefined step: "I should see the "Edit Proeject" link" (Cucumber::Undefined) 
     features/hidden_links.feature:26:in `Then I should see the "Edit Proeject" link' 

    Scenario: Delete project link is hidden for non-signed-in users # features/hidden_links.feature:28 
    Given I am on the homepage         # features/step_definitions/web_steps.rb:44 
    When I follow "TextMate 2"         # features/step_definitions/web_steps.rb:56 
     undefined method `admins_only' for #<#<Class:0x9c16994>:0xaa71660> (ActionView::Template::Error) 
     ./app/views/projects/show.html.erb:3:in `_app_views_projects_show_html_erb___713092924_82350660' 
     /home/dexter/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.12/lib/action_view/template.rb:145:in `block in render' 
     ./features/step_definitions/web_steps.rb:57:in `/^(?:|I)follow "([^"]*)"$/' 
     features/hidden_links.feature:30:in `When I follow "TextMate 2"' 
    Then I should not see the "Delete Project" link    # features/hidden_links.feature:31 
     Undefined step: "I should not see the "Delete Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:31:in `Then I should not see the "Delete Project" link' 

    Scenario: Delete project link is hidden for signed-in users # features/hidden_links.feature:33 
    Given I am signed in as "[email protected]"    # features/hidden_links.feature:34 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:34:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"        # features/step_definitions/web_steps.rb:56 
    Then I should not see the "Delete Project" link   # features/hidden_links.feature:36 
     Undefined step: "I should not see the "Delete Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:36:in `Then I should not see the "Delete Project" link' 

    Scenario: Delete project link is shown to admins # features/hidden_links.feature:38 
    Given I am signed in as "[email protected]" # features/hidden_links.feature:39 
     Undefined step: "I am signed in as "[email protected]"" (Cucumber::Undefined) 
     features/hidden_links.feature:39:in `Given I am signed in as "[email protected]"' 
    When I follow "TextMate 2"      # features/step_definitions/web_steps.rb:56 
    Then I should see the "Delete Project" link # features/hidden_links.feature:41 
     Undefined step: "I should see the "Delete Project" link" (Cucumber::Undefined) 
     features/hidden_links.feature:41:in `Then I should see the "Delete Project" link' 

Failing Scenarios: 
cucumber features/hidden_links.feature:13 # Scenario: Edit project link is hidden for non-signed-in users 
cucumber features/hidden_links.feature:28 # Scenario: Delete project link is hidden for non-signed-in users 

6 scenarios (2 failed, 4 undefined) 
30 steps (2 failed, 4 skipped, 10 undefined, 14 passed) 
0m0.748s 

You can implement step definitions for undefined steps with these snippets: 

Then(/^I should not see the "(.*?)" link$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

Given(/^I am signed in as "(.*?)"$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

Then(/^I should see the "(.*?)" link$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

및 그 show.html.erb는 admins_only입니다.

<% title(@project.name, "Projects") %> 
<h2><%= @project.name %></h2> 
<% admins_only do %> 
<%= link_to "Edit Project", edit_project_path(@project) %> 
<%= link_to "Delete Project", @project, :method => :delete, :confirm => "Are you sure you want to delete this project?" %> 
<% end %> 
<%= link_to "New Ticket", new_project_ticket_path(@project) %> 
<ul id= 'tickets'> 
    <% @project.tickets.each do |ticket| %> 
    <li> 
     #<%= ticket.id %> - <%= link_to ticket.title, [@project, ticket] %> 
    </li> 
    <% end %> 
</ul> 

tha ts 무엇을 시도했지만 내 문제를 해결하지 못해 도움을 받으 셨습니다.

답변

1

해당 _steps.rb 파일에서 단계 정의를 구현하지 않았습니다. Web Steps는 일반적인 단계 정의를 제공하지만 끔찍한 요소이므로 사용하면 안됩니다. step_definitions 디렉토리 안에 루비 파일로

Then(/^I should not see the "(.*?)" link$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

Given(/^I am signed in as "(.*?)"$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

Then(/^I should see the "(.*?)" link$/) do |arg1| 
    pending # express the regexp above with the code you wish you had 
end 

, 그리고 단계의 조건을 충족하는 코드로 계류중인 대체 :

은이 붙여 넣어야이 문제를 해결합니다.

+0

그리고 게시 한 코드 안에 '보류 중'단어는 무엇입니까? 나는 그것에 무엇을 더해야하는지 모른다. 또한 'admins_only'에 대해 정의되지 않았으며 책에서 정의해야 할 사항이 무엇인가요? –

+0

프로젝트에 전적으로 달려 있습니다. 레일 앱의 경우 아마도 카피 바라를 사용할 것입니다. 'page.should_not have_link "내 링크"와 같은 것 – DVG

+0

admins_only는 헬퍼 메소드로 정의되어야하지만, 그것은 또 다른 질문입니다. – DVG