开发者

"Suddenly" am getting an Invalid Subclass Error when calling YAML.load_file

开发者 https://www.devze.com 2023-03-17 02:30 出处:网络
I\'m using: Rails 3.0.7 and Rspec 2.5.0 via rvm When I run this spec (using autotest or bundle exec autotest or bundle exec rspec spec/) below:

I'm using: Rails 3.0.7 and Rspec 2.5.0 via rvm

When I run this spec (using autotest or bundle exec autotest or bundle exec rspec spec/) below:

require 'spec_helper'
require 'yaml'

def twitter_feed(id=1) 
   ruby_object = YAML.load_file(::Rails.root.to_s + "/spec/fixtures/feeds/twitter_response_#{id}.yml")
end

I get this:

 Failure/Error: ruby_object = YAML.load_file(::Rails.root.to_s + "/spec/fixtures/feeds/twitter_response_#{id}.yml")
    TypeError:
      invalid subclass
      # ./spec/models/tweet_spec.rb:6:in `twitter_feed'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `transfer'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `node_import'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `load'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:133:in `load'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:144:in `load_file'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:143:in `open'
      # /Users/natebean/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/1.8/yaml.rb:143:in `load_file'
      # ./spec/models/tweet_spec.rb:5:in `twitter_feed'
      # ./spec/models/tweet_spec.rb:58

This "was" working. I can't find any other information on this error on the internet. I've moved from rails 3.0.3 to 3.0.7, but开发者_如何学C don't remember it not working after the upgrade.

Any suggestions? Thanks.


The yaml file I was pulling was looking for Hashie::Mash to map the data to. Up to know I didn't need to require 'hashie', but that has "fixed this problem".

I added to this to my spec and it is now working.

require 'hashie'


Run bundle exec rspec spec --backtrace to get a full backtrace so you can see exactly where that error is coming from.

0

精彩评论

暂无评论...
验证码 换一张
取 消