Rails/RSpec-为Flash通知编写RSpec测试
下面是我的助手显示flash通知的方法 我想写Rspec测试,所以我怎么写呢 请帮帮我Rails/RSpec-为Flash通知编写RSpec测试,rspec,ruby-on-rails-3.2,ruby-on-rails-3.1,rspec-rails,Rspec,Ruby On Rails 3.2,Ruby On Rails 3.1,Rspec Rails,下面是我的助手显示flash通知的方法 我想写Rspec测试,所以我怎么写呢 请帮帮我 def flash_type_to_alert(type) case type when :notice return :success when :info return :info when :alert return :warning when :error return :danger else
def flash_type_to_alert(type)
case type
when :notice
return :success
when :info
return :info
when :alert
return :warning
when :error
return :danger
else
return type
end
end
谢谢,请提前首先,我将改进您的助手删除所有
return
语句并删除案例info
def flash_type_to_alert(type)
case type
when :notice
:success
when :alert
:warning
when :error
:danger
else
type
end
end
您需要的测试如下:
describe "flash_type_to_alert(type)" do
it "defines the success class when flash notice is set" do
expect(helper.flash_type_to_alert(:notice)).to eq(:success)
end
it "defines the warning class when flash alert is set" do
expect(helper.flash_type_to_alert(:alert)).to eq(:warning)
end
it "defines the danger class when flash error is set" do
expect(helper.flash_type_to_alert(:error)).to eq(:danger)
end
it "defines the given class when any other flash is set" do
expect(helper.flash_type_to_alert(:info)).to eq(:info)
end
end