0
如何將固定裝置的使用分離到特定的測試?如何將固定裝置分離到特定的導軌測試
在我的設置中,我的一些測試依賴於夾具數據,有些則沒有,所以在test_helper.rb中使用fixtures :all
加載我所有燈具的默認設置打破了我的測試。
例集成測試:
require 'test_helper'
class WelcomeFlowTest < ActionDispatch::IntegrationTest
test "when no user is found start welcome flow" do
get "/"
follow_redirect!
assert_response :success
post "/setup", {
behaviorist: { name: "Andy", email: "[email protected]" },
habit: { name: "Interval running", on_monday: false, on_tuesday: true, \
on_wednesday: false, on_thursday: true, on_friday: false, \
on_saturday: true, on_sunday: false }
}
assert_response :success
assert_equal 1, Behaviorist.count
assert_equal 1, Habit.count
end
end
我的單元測試,要求行爲主義夾具:
require 'test_helper'
class BehavioristTest < ActiveSupport::TestCase
test "validates uniqueness of :name" do
andy = Behaviorist.new(name: "Andy", remote_ip: "127.0.0.1")
assert_not run.valid?
assert_match /has already been taken/, andy.errors[:name].join
end
end