1

BDD を使用して Rails 3 サイトに機能を実装しようとしています。

Feature: Patents Administration

  Scenario: Patents index
    Given I am on the admin patents page
    Then I should see "Patents"
    And the title should be "Wavetronix - Patents"

そして、対応する手順は次のとおりです。

Given /^I am on the (.*?) page$/ do |text|
  visit eval("#{text.downcase.gsub(/\s/, '_')}_path(locale: 'en')")
end

Then /^I should see "(.*?)"$/ do |text|
  page.must_have_selector('h1', text: text)
end

Then /^the title should be "(.*?)"$/ do |text|
  page.must_have_selector('title', text: text)
end

最初のステップは期待どおりに失敗します: Admin::PatentsController を実装する必要があります。

module Admin
  class PatentsController < BaseController
    before_filter :find_patent

    def index

    end

  private

    def find_patent
      @patent = Patent.find(params[:id]) if params[:id]
    end
  end
end

Admin::BaseController から継承しているため、独自のインデックス アクションとビューがあります。

module Admin
  class BaseController < ApplicationController

    filter_access_to :index

    def index
    end

  end
end

Admin::PatentsController は、そのアクションとビューも継承します。PatentsController のインデックス アクションとビューを明示的に定義して BaseController 実装をオーバーライドすると、ブラウザーで変更が確認できます (新しいインデックス アクションとビューが選択されます)。 BaseController index アクションとビューで。

参照用のコードを追加した Gistを作成しました。

これはバグですか?これをテストするより良い方法はありますか?

4

1 に答える 1

0

ボーンヘッド:テストリクエストが認証されていないためにリダイレクトされている既存の認証メカニズムを考慮していません。

于 2012-09-28T20:23:35.937 に答える