Tuesday, 15 March 2011

ruby - Testing conditions set by around_action in Rails -



ruby - Testing conditions set by around_action in Rails -

in rails app current locale ist set in applicationcontroller through around_action callback. cleaner solution using before_action leave request specific locale hanging around.

class="lang-rb prettyprint-override">class applicationcontroller < actioncontroller::base around_action :with_locale def with_locale i18n.with_locale(find_current_locale) { yield } end end

since current locale reset after request finished not easy access request specific locale in test. before_filter next test pass:

class="lang-rb prettyprint-override">it 'sets locale request' :action, locale: locale i18n.locale.should == locale end

i cannot think of way implement test work around_filter without injecting additional logic controller. there simpler way rspec?

how checking if i18n.with_locale has been called proper parameters.

it 'sets locale request' allow(i18n).to receive(:with_locale) :action, locale: locale expect(i18n).to have_received(:with_locale).with(locale) end

ruby-on-rails ruby testing rspec minitest

No comments:

Post a Comment