4

RSpec と Capybara で OmniAuth をテストしようとしていますが、完全に失敗しています。

これまでのところspec_helper.rb

# Enable omniauth testing mode
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({
                                                            :provider => 'google',
                                                            :uid => '1337',
                                                            :info => {
                                                                'name' => 'JonnieHallman',
                                                                'email' => 'jon@test.com'
                                                            }
                                                        })

そして、Capybara テストを の下に配置する必要があることはわかっていますspec/features。ので、私は持っています:

require 'spec_helper'
describe "Authentications" do
  context "without signing into app" do
    it "sign in button should lead to Google authentication page" do
      visit root_path
      click_link "Login"
      Authentication.last.uid.should == '1337'
    end
  end
end

しかし、私は得る:

1) Authentications without signing into app sign in button should lead to Google authentication page
 Failure/Error: Authentication.last.uid.should == '1337'
 NameError:
   uninitialized constant Authentication
 # ./spec/features/omniauth_spec.rb:10:in `block (3 levels) in <top (required)>'

完全に、完全に失われました。OmniAuth wiki を調べてみましたが、本当に役に立ちませんでした。Stack Overflow で 1 時間以上検索しましたが、うまくいきませんでした。ヘルプ?

4

1 に答える 1

4

かなりの読書をした後、私は最終的にこれを修正することができました。テストは次のようになります。

require 'spec_helper'
describe "Authentications" do
  context "Clicking the login link" do
    it "Login button should log in" do
      visit root_path
      click_link "Login"
      page.should have_link "Logout"
    end
  end
end

単純!

于 2012-12-12T16:33:31.347 に答える