require_relative '../spec_helper' require "rack/test" require 'restpack_web/test_support' include Rack::Test::Methods describe RestPack::Web do let(:app) { RestPack::Web::App.new( lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'hello world'] }, { core_domain: ENV['RESTPACK_CORE_SERVICE'], password: ENV['RESTPACK_ACCESS_KEY'] }) } before do RestPack::Web::TestSupport.stub_restpack_web end it "returns a valid response" do get '/' last_response.ok?.must_equal true last_response.body.must_equal 'hello world' end describe '#add_user' do let(:users_path){ File.expand_path('./spec/fixtures/users.json') } before do stub_request(:get, 'http://auth.restpack-sample.org/api/v1/users/1.json'). to_return(:body => File.read(users_path)) end it 'inject an user into env' do get '/', {}, 'rack.session' => { :user_id => 1 } last_request.env[:restpack][:user_id].must_equal 1 last_request.env[:restpack][:user]['email'].must_equal 'lukasz.krystkowiak@gmail.com' last_request.env[:restpack][:user]['nickname'].must_equal 'lukkry' end end end