这个 Rspec 存根有什么问题?

What is wrong with this Rspec stub?

我已经删除了我的 API 客户。并且已经达到 return 预期的哈希值。但是我无法访问实际的哈希本身。

例如

puts page # returns {:access_token=>"blah", :name=>"parrotcafe", :fb_id=>"2131231", :perms=>"ADMINISTER"}

但是

puts page['perms'] # returns nil instead of 'ADMINISTER'

这是我的 Rspec:

  describe 'all' do
    it 'if doesnt exist, it should create authentication' do
      request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook]

      client = double("koala client")
      Koala::Facebook::API.stub(:new).and_return(client)
      allow(client).to receive_messages(get_connections: [{'access_token': 'blah', 'name': 'parrot', 'fb_id': '2131231', 'perms': 'ADMINISTER'}])
      expect {
        post :all, provider: :facebook
      }.to change{ Authentication.count }.by(1)
    end
  end

这是失败的实际代码。:

  @user_graph = Koala::Facebook::API.new(authentication.token)
  pages = @user_graph.get_connections('me', 'accounts')
  pages.each do |page|
    Page.create(user_id: self.id, access_token: page['access_token'], name: page['name'], fb_id: page['id']) if page['perms'].include? "ADMINISTER"
  end

发现问题是我应该改用字典:

allow(client).to receive_messages(get_connections: [{'access_token' => 'blah', 'name' => 'parrotcafe', 'fb_id' => '2131231', 'perms' => 'ADMINISTER'}])