require File.expand_path(File.dirname(__FILE__) + '../../spec_helper') #require 'hello_world' # <-- your sinatra app require 'rspec' require 'rack/test' require 'dotenv' Dotenv.load describe 'Server App' do include Rack::Test::Methods let(:body) { { :ref=>"refs/heads/another-branch" }.to_json } let(:user_api) { Octokit::Client.new( login: ENV['LOGIN'], access_token: ENV['ACCESS_TOKEN'] ) } let(:file){ f = File.expand_path(File.dirname(__FILE__) + '/../fixtures/.travis.yml') Travis::Yaml.parse( File.open(f).read ) } def app a = Perkins::Server a.set :perkins_application, perkins_app a.set :github_options, { :scopes => "admin:repo_hook,repo,user:email", :secret => perkins_app.github_client_secret, :client_id => perkins_app.github_client_id, } end context "with app" do before do @user = make_user('login' => 'michelson') login_as @user end it "index" do get '/' expect(last_response).to be_ok end it "show config" do get "/config" expect(last_response).to be_ok expect(last_response.body).to include("github_client_id") end it "profile" do allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api) get "/me" #puts last_response.body expect(last_response).to be_ok end describe "github" do it "sync" do allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api) get "/repos/sync" follow_redirect! expect("http://example.org/me").to be == last_request.url expect(last_response).to be_ok expect(Perkins::Repo.synced_records).to be_any end it "add repo" do allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api) a = Warden::GitHub::User.new Perkins::Repo.sync_github_repos(a) repo = Perkins::Repo.synced_records.first get "/repos/add/#{repo.gb_id}" follow_redirect! expect("http://example.org/me").to be == last_request.url expect(last_response).to be_ok expect(Perkins::Repo.find(repo.id).github_data).to_not be_blank end it "find a repo" do allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api) a = Warden::GitHub::User.new Perkins::Repo.sync_github_repos(a) allow_any_instance_of(Perkins::Repo).to receive(:check_config_existence).and_return(file) get "/repos/#{Perkins::Repo.last.github_data["full_name"]}" expect(last_response.body).to include(Perkins::Repo.last.name) end it "receive hook" do end end end end