1

使用 minitest,测试这个 build_plan 方法的最佳方法是什么?

我目前的尝试是尝试验证 @account.plan 是否已设置,但我不太清楚如何做到这一点。这是我应该尝试做的,还是别的什么?

account_controller.rb

class AccountsController < ApplicationController

  before_filter :build_plan, :only => [:new, :create]

  def build_plan
    redirect_to '/app/signup' and return unless @plan = SubscriptionPlan.find_by_name(params[:plan])
    @plan.discount  = @discount
    @account.plan   = @plan
  end
end

account_integration_test.rb

require 'minitest_helper'

describe "Account integration" do

  before do
    @account = Factory.build(:account)
  end

  def fill_in_info
    fill_in 'First name', :with => @account.admin.first
    fill_in 'Last name', :with => @account.admin.last
    fill_in 'Email', :with => @account.admin.email
  end

  describe "register" do
    it "should set plan" do
      visit signup_path(:plan => "small_group")
      fill_in_info
      click_button 'Create Account'
      @account.plan.must_be_kind_of SubscriptionPlan #this doesn't work -- @account.plan is nil
    end
  end
end
4

1 回答 1

0

对于验收测试,请确保您在“minitest_helper”中包含正确的(可能是 Capybara)DSL,例如

class MiniTest::Spec

  include Capybara::DSL
  ...
end

值得阅读其他一些 StackOverflow 帖子以获得正确的帮助设置。这个有没有人在 Rails 功能测试中使用过 Minitest::Spec?对我有帮助。

这是我的功能测试测试助手的要点(我还没有像上面那样添加 Capybara 模块)https://gist.github.com/2990759

于 2012-06-28T13:57:35.153 回答