Skip to content
Extraits de code Groupes Projets
oauth_steps.rb 2,02 ko
Newer Older
  • Learn to ignore specific revisions
  •   Chubbies.run unless Chubbies.running?
    end
    
    Given /^Chubbies has been killed$/ do
      Chubbies.ensure_killed
    
    end
    
    Given /^Chubbies is registered on my pod$/ do
      OAuth2::Provider.client_class.create! :name => 'Chubbies',
        :oauth_identifier => 'abcdefgh12345678',
        :oauth_secret => 'secret'
    end
    
    And /^I should see my "([^"]+)"/ do |code|
      page.should have_content(@me.person.instance_eval(code).to_s)
    end
    
    When /^I try to authorize Chubbies$/ do
    
      # We need to reset the tokens saved in Chubbies,
      # as we are clearing the Diaspora DB every scenario
      Then 'I visit "/reset" on Chubbies'
      Then 'I visit "/" on Chubbies'
      ###
    
      And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\""
      And 'I press "Log in with Diaspora"'
    
      Then 'I should be on the new user session page'
      And "I fill in \"Username\" with \"#{@me.username}\""
      And "I fill in \"Password\" with \"#{@me.password}\""
      And 'I press "Sign in"'
      Then 'I should be on the oauth authorize page'
    end
    
    When /^I visit "([^"]+)" on Chubbies$/ do |path|
    
      former_host = Capybara.app_host
      Capybara.app_host = "localhost:#{Chubbies::PORT}"
      visit(path)
      Capybara.app_host = former_host
    end
    
    class Chubbies
      PORT = 9292
    
      def self.run
        @pid = fork do
    
          Process.exec "cd #{Rails.root}/spec/chubbies/ && BUNDLE_GEMFILE=Gemfile DIASPORA_PORT=9887 bundle exec rackup -p #{PORT} 2> /dev/null"
    
        while(!running?) do
          sleep(1)
        end
      end
    
      def self.kill
        `kill -9 #{get_pid}`
      end
    
    
      def self.ensure_killed
        if !(@killed) && self.running?
          self.kill
          @killed = true
        end
      end
    
    
      def self.running?
        begin
          RestClient.get("localhost:#{PORT}")
          true
        rescue Errno::ECONNREFUSED
          false
        end
      end
    
      def self.get_pid
        @pid ||= lambda {
          processes = `ps -ax -o pid,command | grep "rackup -p #{PORT}"`.split("\n")
          processes = processes.select{|p| !p.include?("grep") }
          processes.first.split(" ").first
        }.call
      end
    end