Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of 'faker' gem requires Ruby versions > 1.8.7 #157

Closed
stanhu opened this issue Sep 17, 2012 · 4 comments
Closed

Use of 'faker' gem requires Ruby versions > 1.8.7 #157

stanhu opened this issue Sep 17, 2012 · 4 comments

Comments

@stanhu
Copy link

stanhu commented Sep 17, 2012

The default Ubuntu 12.04 installation has Ruby 1.8.7 installed by default. While running 'rake'' under Ruby v1.8.7, I got the following error messages:

Failures:

  1) GitCommitNotifier::Emailer new should assign parameters from options
     Failure/Error: options[name.to_sym] = Faker::Lorem.sentence
     NoMethodError:
       undefined method `downcase' for :en:Symbol
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:22
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:21:in `each'
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:21

  2) GitCommitNotifier::Emailer payload should produce a valid json payload
     Failure/Error: options[name.to_sym] = Faker::Lorem.sentence
     NoMethodError:
       undefined method `downcase' for :en:Symbol
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:35
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:34:in `each'
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:34

  3) GitCommitNotifier::Emailer new should assign parameters from options
     Failure/Error: options[name.to_sym] = Faker::Lorem.sentence
     NoMethodError:
       undefined method `downcase' for :en:Symbol
     # ./spec/lib/git_commit_notifier/emailer_spec.rb:22
     # ./spec/lib/git_commit_notifier/emailer_spec.rb:21:in `each'
     # ./spec/lib/git_commit_notifier/emailer_spec.rb:21

  4) GitCommitNotifier::Emailer mail_html_message should form inline html
     Failure/Error: options[name.to_sym] = Faker::Lorem.sentence
     NoMethodError:
       undefined method `downcase' for :en:Symbol
     # ./spec/lib/git_commit_notifier/emailer_spec.rb:54
     # ./spec/lib/git_commit_notifier/emailer_spec.rb:53:in `each'
     # ./spec/lib/git_commit_notifier/emailer_spec.rb:53

  5) GitCommitNotifier::Logger log_directory should be custom if debug and custom directory specified
     Failure/Error: expected = Faker::Lorem.sentence
     NoMethodError:
       undefined method `downcase' for :en:Symbol
     # ./spec/lib/git_commit_notifier/logger_spec.rb:32

Finished in 0.55793 seconds
81 examples, 5 failures

Failed examples:

rspec ./spec/lib/git_commit_notifier/webhook_spec.rb:19 # GitCommitNotifier::Emailer new should assign parameters from options
rspec ./spec/lib/git_commit_notifier/webhook_spec.rb:32 # GitCommitNotifier::Emailer payload should produce a valid json payload
rspec ./spec/lib/git_commit_notifier/emailer_spec.rb:19 # GitCommitNotifier::Emailer new should assign parameters from options
rspec ./spec/lib/git_commit_notifier/emailer_spec.rb:51 # GitCommitNotifier::Emailer mail_html_message should form inline html
rspec ./spec/lib/git_commit_notifier/logger_spec.rb:31 # GitCommitNotifier::Logger log_directory should be custom if debug and custom directory specified
rake aborted!
/usr/bin/ruby1.8 -S rspec ./spec/lib/git_commit_notifier/webhook_spec.rb ./spec/lib/git_commit_notifier/emailer_spec.rb ./spec/lib/git_commit_notifier/git_spec.rb ./spec/lib/git_commit_notifier/diff_to_html_spec.rb ./spec/lib/git_commit_notifier/commit_hook_spec.rb ./spec/lib/git_commit_notifier/result_processor_spec.rb ./spec/lib/git_commit_notifier/logger_spec.rb failed

Tasks: TOP => default => spec

Upon further investigation, I found that Faker::Config.locale attempts to use downcase, a method that isn't isn't present in Ruby v1.8.7 but in v1.9+:

module Faker class Config @locale = nil
class << self
  attr_writer :locale
  def locale
    @locale || I18n.locale.downcase
  end
end

end

Since the locale isn't defined by default, the downcase call fails.

The first obvious workaround is to set the locale in spec_helper.rb:

Faker::Config.locale = "en-us"

Unfortunately, load_yml on the Japanese YML (ja.yml) fails to load on Ruby 1.8.7 for some reason.

When I upgraded to Ruby v1.9.1, everything worked fine.

Might it be time to require Ruby >= v1.9.1?

@akzhan
Copy link
Member

akzhan commented Sep 18, 2012

Thanks for point to this. Now workarounded by eaab807.

@akzhan akzhan closed this as completed Sep 18, 2012
@stanhu
Copy link
Author

stanhu commented Sep 18, 2012

Thanks for the fix. I think you also need to bump faker to 1.1.1 because I still get this error:

$ /usr/bin/ruby1.8 -S rspec ./spec/lib/git_commit_notifier/webhook_spec.rb
..F
Failures:
  1) GitCommitNotifier::Emailer new should assign parameters from options
     Failure/Error: options[name.to_sym] = Faker::Lorem.sentence
     ArgumentError:
       syntax error on line 4, col 586: `      state: ["北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"]'
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:22
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:21:in `each'
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:21
  2) GitCommitNotifier::Emailer payload should produce a valid json payload
     Failure/Error: options[name.to_sym] = Faker::Lorem.sentence
     ArgumentError:
       syntax error on line 4, col 586: `      state: ["北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"]'
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:35
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:34:in `each'
     # ./spec/lib/git_commit_notifier/webhook_spec.rb:34

Turns out ja.yml in faker's locale directory isn't parsed happily in Ruby 1.8.7. There is a fix for this now:

faker-ruby/faker@6423fef

When I upgraded to faker 1.1.1, running 'rake' under Ruby v1.8.7 worked fine.

@stanhu
Copy link
Author

stanhu commented Sep 19, 2012

FYI, Faker 1.1.2 now has your workaround in place, so it can be removed if you so desire:

faker-ruby/faker@0a1f50c

@akzhan
Copy link
Member

akzhan commented Sep 19, 2012

Thanks, removed monkey patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants