2014-04-25 2 views
2

rspec으로 다른 도우미를 테스트 할 때 멋진 글꼴 fa_icon 도우미 사용에 문제가 있습니다. 앱 내에서 도우미 내의 도우미는 의도 한대로 작동합니다. 그러나, 우리가 도우미에 대한 우리의 rspec 테스트를 실행할 때 fa_icon 실패합니다. 여기rspec에서 글꼴 - awesome-rails 도우미가 없습니다.

def helper 
    if condition 
    fa_icon "some-icon" 
    else 
    fa_icon "some-other-icon" 
    end 
end 

fa_icon 정의되지 않은 방법을 알리는 실패 중 하나입니다

이 도우미가하는 일의 단순화 된 버전입니다.

Failures: 

    1) ApplicationHelper#risk_flag risk level is below 3 
    Failure/Error: subject { risk_flag(risk_level) } 
    NoMethodError: 
     undefined method `fa_icon' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4::Nested_1:0x000000081ed900> 
    # ./app/helpers/application_helper.rb:84:in `risk_flag' 
    # ./spec/helpers/application_helper_spec.rb:79:in `block (3 levels) in <top (required)>' 
    # ./spec/helpers/application_helper_spec.rb:83:in `block (4 levels) in <top (required)>' 

특별한 방법으로 사양 지원 파일에 font-awesome-rails를 포함해야합니까? 나는 그것을 모든 환경의 Gemfile에 포함 시켰습니다.

현재 여기에 루비 2.1.1p176를 사용하는 것은 어떤 도움을 주시면 감사하겠습니다 bundle list | grep '\(rails\)\|\(awesome\)'

Gems included by the bundle: 
    * actionmailer (4.0.4) 
    * actionpack (4.0.4) 
    * activemodel (4.0.4) 
    * activerecord (4.0.4) 
    * activerecord-deprecated_finders (1.0.3) 
    * activesupport (4.0.4) 
    * acts-as-taggable-on (3.1.1) 
    * addressable (2.3.6) 
    * arel (4.0.2) 
    * bcrypt (3.1.7) 
    * bourbon (3.2.0) 
    * builder (3.1.4) 
    * bullet (4.8.0) 
    * bundler (1.6.1) 
    * cancan (1.6.10) 
    * capybara (2.2.1) 
    * capybara-webkit (1.1.0) 
    * chosen-rails (1.1.0) 
    * chunky_png (1.3.0) 
    * coderay (1.1.0) 
    * coffee-rails (4.0.1) 
    * coffee-script (2.2.0) 
    * coffee-script-source (1.7.0) 
    * compass (0.12.6) 
    * compass-rails (1.1.7) 
    * countries (0.9.3) 
    * css_parser (1.3.5) 
    * cucumber (1.3.14) 
    * cucumber-rails (1.4.0) 
    * currencies (0.4.2) 
    * daemons (1.1.9) 
    * database_cleaner (1.2.0) 
    * devise (3.2.4) 
    * diff-lcs (1.2.5) 
    * docile (1.1.3) 
    * dotenv (0.11.0) 
    * dotenv-deployment (0.0.1) 
    * easy_translate (0.5.0) 
    * erubis (2.7.0) 
    * eventmachine (1.0.3) 
    * execjs (2.0.2) 
    * factory_girl (4.4.0) 
    * factory_girl_rails (4.4.1) 
    * faker (1.3.0) 
    * fakeweb (1.3.0) 
    * font-awesome-rails (4.0.3.1) 
    * foreman (0.63.0) 
    * fssm (0.2.10) 
    * geocoder (1.2.0) 
    * gherkin (2.12.2) 
    * globalize (4.0.1) 
    * headless (1.0.1) 
    * highline (1.6.21) 
    * hike (1.2.3) 
    * i18n (0.6.9) 
    * i18n-tasks (0.3.11) 
    * jquery-placeholder-rails (2.0.7) 
    * jquery-rails (3.1.0) 
    * jquery-ui-rails (4.2.1) 
    * json (1.8.1) 
    * jwt (0.1.11) 
    * kaminari (0.15.1) 
    * kgio (2.9.2) 
    * launchy (2.4.2) 
    * libv8 (3.16.14.3) 
    * mail (2.5.4) 
    * memcachier (0.0.2) 
    * method_source (0.8.2) 
    * mime-types (1.25.1) 
    * mini_portile (0.5.3) 
    * minitest (4.7.5) 
    * multi_json (1.9.2) 
    * multi_test (0.1.1) 
    * neat (1.5.1) 
    * nokogiri (1.6.1) 
    * normalize-rails (3.0.1) 
    * orm_adapter (0.5.0) 
    * pg (0.17.1) 
    * phony (2.2.5) 
    * phony_rails (0.6.1) 
    * polyglot (0.3.4) 
    * pry (0.9.12.6) 
    * pry-rails (0.3.2) 
    * quiet_assets (1.0.2) 
    * rack (1.5.2) 
    * rack-test (0.6.2) 
    * railroady (1.1.1) 
    * rails (4.0.4) 
    * rails_12factor (0.0.2) 
    * rails_serve_static_assets (0.0.2) 
    * rails_stdout_logging (0.0.3) 
    * railties (4.0.4) 
    * raindrops (0.13.0) 
    * rake (10.3.1) 
    * ref (1.0.5) 
    * roadie (2.4.3) 
    * rspec-core (2.14.8) 
    * rspec-expectations (2.14.5) 
    * rspec-mocks (2.14.6) 
    * rspec-rails (2.14.2) 
    * sass (3.2.19) 
    * sass-rails (4.0.3) 
    * selectivizr-rails (1.1.2) 
    * shoulda-matchers (2.6.0) 
    * simple_form (3.0.2) 
    * simplecov (0.8.2) 
    * simplecov-html (0.8.0) 
    * simplecov-rcov (0.2.3) 
    * slop (3.5.0) 
    * sprockets (2.10.1) 
    * sprockets-rails (2.0.1) 
    * term-ansicolor (1.3.0) 
    * terminal-table (1.4.5) 
    * therubyracer (0.12.1) 
    * thin (1.6.2) 
    * thor (0.19.1) 
    * thread (0.1.4) 
    * thread_safe (0.3.3) 
    * tilt (1.4.1) 
    * timecop (0.7.1) 
    * tins (1.1.0) 
    * treetop (1.4.15) 
    * twilio-ruby (3.11.5) 
    * tzinfo (0.3.39) 
    * uglifier (2.5.0) 
    * unicorn (4.8.2) 
    * uniform_notifier (1.4.0) 
    * warden (1.2.3) 
    * xpath (2.0.0) 

의 출력이다. 고맙습니다!

답변

3

RSpec에 사람은 내 문제를 해결할 수 있었다 :

https://github.com/rspec/rspec-rails/issues/1007#issuecomment-41510827

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 

주요 변화는 내가 떨어져 내 도우미를 호출 할 필요가 있다는 것을 helper

관련 문제