Rails 2.2.2 を使用していますが、どのように params 値を設定してヘルパー メソッドをテストできるのか疑問に思っています。
ヘルパー メソッドを使用してテストを実行できる例をいくつか見つけましたが、メソッドで request または params の値を直接使用するとうまくいきません。
require 'test_helper'
class ProductHelperTest < Test::Unit::TestCase
include ProductHelper
context 'ProductHelper' do
should 'build the link' do
assert_equal '', build_link
end
end
end
request または params 値を使用すると、ローカル変数またはメソッドが未定義であるというエラーが表示されます。値を設定するにはどうすればよいですか?
request 値を使用すると shoulda からエラーが発生し、params 値を使用すると同じメッセージになります。
1) Error:
test: ProductHelper should build the link. (ProductHelperTest):
NameError: undefined local variable or method `request` for #<ProductHelperTest:0x33ace6c>
/vendor/rails/actionpack/lib/action_controller/test_process.rb:471:in `method_missing`
/app/helpers/products_helper.rb:14:in `build_link`
./test/unit/product_helper_test.rb:10:in `__bind_1251902384_440357`
/vendor/gems/thoughtbot-shoulda-2.0.5/lib/shoulda/context.rb:254:in `call`
/vendor/gems/thoughtbot-shoulda-2.0.5/lib/shoulda/context.rb:254:in `test: ProductHelper should build the link. `
/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `__send__`
/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:94:in `run`