Closed GolfyMcG closed 10 years ago
Can you create a new simple helper with just your sample and a new spec doing a simple test on it?
I tried locally and I have no issues. I locked into Ruby 2.1.1 and your same rspec gem versions, as well as your font-awesome-rails version.
So, I solved the problem but accidentally deleted one line and closed out my vim without it checked into version control and I can't recall what I had. These are the relevant bits:
def risk_flag(risk_level)
icon_name = if risk_level > 5
"frown-o"
elsif risk_level >= 3 && risk_level <= 5
"meh-o"
else
"smile-o"
end
fa_icon(icon_name)
end
describe "#risk_flag" do
subject { risk_flag(risk_level) }
context "risk level is below 3" do
let(:risk_level) { 2 }
it "should call fa_icon smile" do
should eq("<i class=\"fa fa-smile-o\"></i>")
end
end
end
RSpec.configure do |config|
config.include FontAwesome::Rails::IconHelper
end
This last snippet is the problem. I'm trying to include the fa_icon module, but I can't seem to remember what I had written to include it. The module, if you viewed it in the font-awesome-rails repo would make you think it should be FontAwesome::Rails::IconHelper
but it says that's an invalid constant.
@GolfyMcG I see what's going on here. You need to execute your test in the context of the helper instance:
require 'spec_helper'
describe ApplicationHelper do
describe "#risk_flag" do
context "with risk level below 3" do
it "generates a smile icon" do
expect(helper.risk_flag(2)).to eq("<i class=\"fa fa-smile-o\"></i>")
end
end
end
end
Check out the Relish docs on helper specs: https://www.relishapp.com/rspec/rspec-rails/v/2-14/docs/helper-specs/helper-spec
You won't need config.include FontAwesome::Rails::IconHelper
in your spec helper.
Sorry for not including the entire file but this is within the block you specified....
@GolfyMcG Not sure I follow? I included my full application_helper_spec.rb
so you could see what I used. The solution is using helper.risk_flag(...)
instead of the bare risk_flag(...)
.
My apologies! It was the change in syntax of the test that I didn't see:
should eq("<i class=\"fa fa-smile-o\"></i>")
to
expect(helper.risk_flag(2)).to eq("<i class=\"fa fa-smile-o\"></i>")
All green! Thank you! You rock!
I'm experiencing a problem with using the font awesome
fa_icon
helper when testing another helper with rspec. Within the app, the helper within the helper, works as intended; however, when I run our rspec tests for the helper that usesfa_icon
it fails.This is a simplified version of what the helper does:
Here is one of the failures stating that
fa_icon
is an undefined method.Do I need to include font-awesome-rails in the spec support files in some special way? I've included it in the Gemfile in all environments.
Currently using ruby 2.1.1p176 and here is the output from
bundle list | grep '\(rails\)\|\(awesome\)'
Any help would be appreciated. Thank you!