vkontakte_api 1.1 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +1 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +13 -10
- data/Rakefile +2 -2
- data/lib/vkontakte_api/api.rb +3 -2
- data/lib/vkontakte_api/authorization.rb +5 -5
- data/lib/vkontakte_api/client.rb +17 -17
- data/lib/vkontakte_api/configuration.rb +8 -3
- data/lib/vkontakte_api/error.rb +9 -0
- data/lib/vkontakte_api/logger.rb +1 -1
- data/lib/vkontakte_api/namespaces.yml +3 -0
- data/lib/vkontakte_api/resolver.rb +11 -3
- data/lib/vkontakte_api/version.rb +1 -1
- data/spec/integration_spec.rb +25 -23
- data/spec/spec_helper.rb +2 -0
- data/spec/support/mechanized_authorization.rb +57 -0
- data/spec/vkontakte_api/api_spec.rb +11 -11
- data/spec/vkontakte_api/authorization_spec.rb +26 -26
- data/spec/vkontakte_api/client_spec.rb +3 -3
- data/spec/vkontakte_api/error_spec.rb +10 -10
- data/spec/vkontakte_api/logger_spec.rb +4 -4
- data/spec/vkontakte_api/method_spec.rb +7 -7
- data/spec/vkontakte_api/resolvable_spec.rb +4 -4
- data/spec/vkontakte_api/resolver_spec.rb +26 -12
- data/spec/vkontakte_api/result_spec.rb +13 -13
- data/spec/vkontakte_api/uploading_spec.rb +12 -12
- data/spec/vkontakte_api/utils_spec.rb +6 -6
- data/spec/vkontakte_api_spec.rb +1 -1
- data/vkontakte_api.gemspec +5 -2
- metadata +40 -51
| @@ -2,11 +2,11 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe VkontakteApi::API do
         | 
| 4 4 | 
             
              def create_connection
         | 
| 5 | 
            -
                @result = {'response' => {'key' => 'value'}}
         | 
| 5 | 
            +
                @result = { 'response' => { 'key' => 'value' } }
         | 
| 6 6 |  | 
| 7 7 | 
             
                @connection = Faraday.new do |builder|
         | 
| 8 8 | 
             
                  builder.response :mashify
         | 
| 9 | 
            -
                  builder.response :oj, : | 
| 9 | 
            +
                  builder.response :oj, preserve_raw: true
         | 
| 10 10 | 
             
                  builder.adapter  :test do |stub|
         | 
| 11 11 | 
             
                    stub.post('/apiMethod') do
         | 
| 12 12 | 
             
                      [200, {}, Oj.dump(@result)]
         | 
| @@ -23,8 +23,8 @@ describe VkontakteApi::API do | |
| 23 23 |  | 
| 24 24 | 
             
                context "called with a token parameter" do
         | 
| 25 25 | 
             
                  it "sends it to .connection" do
         | 
| 26 | 
            -
                    subject.should_receive(:connection).with(: | 
| 27 | 
            -
                    subject.call('apiMethod', {: | 
| 26 | 
            +
                    subject.should_receive(:connection).with(url: VkontakteApi::API::URL_PREFIX, token: 'token')
         | 
| 27 | 
            +
                    subject.call('apiMethod', { some: :params }, 'token')
         | 
| 28 28 | 
             
                  end
         | 
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| @@ -33,10 +33,10 @@ describe VkontakteApi::API do | |
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 35 | 
             
                it "uses an HTTP verb from VkontakteApi.http_verb" do
         | 
| 36 | 
            -
                  http_verb =  | 
| 36 | 
            +
                  http_verb = double("HTTP verb")
         | 
| 37 37 | 
             
                  VkontakteApi.http_verb = http_verb
         | 
| 38 38 |  | 
| 39 | 
            -
                  response =  | 
| 39 | 
            +
                  response = double("Response", body: double)
         | 
| 40 40 | 
             
                  @connection.should_receive(:send).with(http_verb, 'apiMethod', {}).and_return(response)
         | 
| 41 41 | 
             
                  subject.call('apiMethod')
         | 
| 42 42 | 
             
                end
         | 
| @@ -48,11 +48,11 @@ describe VkontakteApi::API do | |
| 48 48 |  | 
| 49 49 | 
             
              describe ".connection" do
         | 
| 50 50 | 
             
                it "uses the :url parameter and VkontakteApi.faraday_options" do
         | 
| 51 | 
            -
                  faraday_options =  | 
| 51 | 
            +
                  faraday_options = double("Faraday options")
         | 
| 52 52 | 
             
                  VkontakteApi.stub(:faraday_options).and_return(faraday_options)
         | 
| 53 | 
            -
                  url =  | 
| 53 | 
            +
                  url = double("URL")
         | 
| 54 54 | 
             
                  Faraday.should_receive(:new).with(url, faraday_options)
         | 
| 55 | 
            -
                  connection = subject.connection(: | 
| 55 | 
            +
                  connection = subject.connection(url: url)
         | 
| 56 56 | 
             
                end
         | 
| 57 57 |  | 
| 58 58 | 
             
                context "without a token" do
         | 
| @@ -64,11 +64,11 @@ describe VkontakteApi::API do | |
| 64 64 |  | 
| 65 65 | 
             
                context "with a token" do
         | 
| 66 66 | 
             
                  before(:each) do
         | 
| 67 | 
            -
                    @token =  | 
| 67 | 
            +
                    @token = double("Token")
         | 
| 68 68 | 
             
                  end
         | 
| 69 69 |  | 
| 70 70 | 
             
                  it "creates a connection with an oauth2 middleware" do
         | 
| 71 | 
            -
                    connection = subject.connection(: | 
| 71 | 
            +
                    connection = subject.connection(token: @token)
         | 
| 72 72 | 
             
                    handler = connection.builder.handlers.first
         | 
| 73 73 | 
             
                    handler.name.should == 'FaradayMiddleware::OAuth2'
         | 
| 74 74 | 
             
                    handler.instance_variable_get(:@args).should == [@token]
         | 
| @@ -2,21 +2,21 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe VkontakteApi::Authorization do
         | 
| 4 4 | 
             
              before(:each) do
         | 
| 5 | 
            -
                @app_id =  | 
| 5 | 
            +
                @app_id = double("App id")
         | 
| 6 6 | 
             
                VkontakteApi.stub(:app_id).and_return(@app_id)
         | 
| 7 | 
            -
                @app_secret =  | 
| 7 | 
            +
                @app_secret = double("App secret")
         | 
| 8 8 | 
             
                VkontakteApi.stub(:app_secret).and_return(@app_secret)
         | 
| 9 | 
            -
                @redirect_uri =  | 
| 9 | 
            +
                @redirect_uri = double("Redirect uri")
         | 
| 10 10 | 
             
                VkontakteApi.stub(:redirect_uri).and_return(@redirect_uri)
         | 
| 11 11 |  | 
| 12 | 
            -
                @url   =  | 
| 13 | 
            -
                @token =  | 
| 12 | 
            +
                @url   = double("Authorization url")
         | 
| 13 | 
            +
                @token = double("Token")
         | 
| 14 14 |  | 
| 15 | 
            -
                @auth_code          =  | 
| 16 | 
            -
                @implicit           =  | 
| 17 | 
            -
                @client_credentials =  | 
| 15 | 
            +
                @auth_code          = double("Authorization code strategy", get_token: @token, authorize_url: @url)
         | 
| 16 | 
            +
                @implicit           = double("Implicit strategy",           authorize_url: @url)
         | 
| 17 | 
            +
                @client_credentials = double("Client credentials strategy", get_token: @token)
         | 
| 18 18 |  | 
| 19 | 
            -
                @client =  | 
| 19 | 
            +
                @client = double("OAuth2::Client instance", auth_code: @auth_code, implicit: @implicit, client_credentials: @client_credentials)
         | 
| 20 20 | 
             
                OAuth2::Client.stub(:new).and_return(@client)
         | 
| 21 21 |  | 
| 22 22 | 
             
                @auth = Object.new
         | 
| @@ -30,34 +30,34 @@ describe VkontakteApi::Authorization do | |
| 30 30 |  | 
| 31 31 | 
             
                context "with a site type" do
         | 
| 32 32 | 
             
                  it "returns a valid authorization url" do
         | 
| 33 | 
            -
                    @auth_code.should_receive(:authorize_url).with(: | 
| 34 | 
            -
                    @auth.authorization_url(: | 
| 33 | 
            +
                    @auth_code.should_receive(:authorize_url).with(redirect_uri: @redirect_uri)
         | 
| 34 | 
            +
                    @auth.authorization_url(type: :site).should == @url
         | 
| 35 35 | 
             
                  end
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| 38 38 | 
             
                context "with a client type" do
         | 
| 39 39 | 
             
                  it "returns a valid authorization url" do
         | 
| 40 | 
            -
                    @implicit.should_receive(:authorize_url).with(: | 
| 41 | 
            -
                    @auth.authorization_url(: | 
| 40 | 
            +
                    @implicit.should_receive(:authorize_url).with(redirect_uri: @redirect_uri)
         | 
| 41 | 
            +
                    @auth.authorization_url(type: :client).should == @url
         | 
| 42 42 | 
             
                  end
         | 
| 43 43 | 
             
                end
         | 
| 44 44 |  | 
| 45 45 | 
             
                context "given a redirect_uri" do
         | 
| 46 46 | 
             
                  it "prefers the given uri over VkontakteApi.redirect_uri" do
         | 
| 47 47 | 
             
                    redirect_uri = 'http://example.com/oauth/callback'
         | 
| 48 | 
            -
                    @auth_code.should_receive(:authorize_url).with(: | 
| 49 | 
            -
                    @auth.authorization_url(: | 
| 48 | 
            +
                    @auth_code.should_receive(:authorize_url).with(redirect_uri: redirect_uri)
         | 
| 49 | 
            +
                    @auth.authorization_url(redirect_uri: redirect_uri)
         | 
| 50 50 | 
             
                  end
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 53 | 
             
                context "given a scope" do
         | 
| 54 54 | 
             
                  it "sends it to VkontakteApi::Utils.flatten_argument" do
         | 
| 55 | 
            -
                    scope =  | 
| 56 | 
            -
                    flat_scope =  | 
| 55 | 
            +
                    scope = double("Scope")
         | 
| 56 | 
            +
                    flat_scope = double("Flat scope")
         | 
| 57 57 |  | 
| 58 58 | 
             
                    VkontakteApi::Utils.should_receive(:flatten_argument).with(scope).and_return(flat_scope)
         | 
| 59 | 
            -
                    @auth_code.should_receive(:authorize_url).with(: | 
| 60 | 
            -
                    @auth.authorization_url(: | 
| 59 | 
            +
                    @auth_code.should_receive(:authorize_url).with(redirect_uri: @redirect_uri, scope: flat_scope)
         | 
| 60 | 
            +
                    @auth.authorization_url(scope: scope)
         | 
| 61 61 | 
             
                  end
         | 
| 62 62 | 
             
                end
         | 
| 63 63 | 
             
              end
         | 
| @@ -65,33 +65,33 @@ describe VkontakteApi::Authorization do | |
| 65 65 | 
             
              describe "#authorize" do
         | 
| 66 66 | 
             
                context "with a site type" do
         | 
| 67 67 | 
             
                  before(:each) do
         | 
| 68 | 
            -
                    @code =  | 
| 68 | 
            +
                    @code = double("Authorization code")
         | 
| 69 69 | 
             
                    @auth_code.stub(:get_token).and_return(@token)
         | 
| 70 70 | 
             
                  end
         | 
| 71 71 |  | 
| 72 72 | 
             
                  it "gets the token" do
         | 
| 73 | 
            -
                    @auth_code.should_receive(:get_token).with(@code,  | 
| 74 | 
            -
                    @auth.authorize(: | 
| 73 | 
            +
                    @auth_code.should_receive(:get_token).with(@code, redirect_uri: @redirect_uri)
         | 
| 74 | 
            +
                    @auth.authorize(type: :site, code: @code)
         | 
| 75 75 | 
             
                  end
         | 
| 76 76 | 
             
                end
         | 
| 77 77 |  | 
| 78 78 | 
             
                context "with an app_server type" do
         | 
| 79 79 | 
             
                  it "gets the token" do
         | 
| 80 | 
            -
                    @client_credentials.should_receive(:get_token).with({: | 
| 81 | 
            -
                    @auth.authorize(: | 
| 80 | 
            +
                    @client_credentials.should_receive(:get_token).with({ redirect_uri: @redirect_uri }, subject::OPTIONS[:client_credentials])
         | 
| 81 | 
            +
                    @auth.authorize(type: :app_server)
         | 
| 82 82 | 
             
                  end
         | 
| 83 83 | 
             
                end
         | 
| 84 84 |  | 
| 85 85 | 
             
                context "with an unknown type" do
         | 
| 86 86 | 
             
                  it "raises an ArgumentError" do
         | 
| 87 87 | 
             
                    expect {
         | 
| 88 | 
            -
                      @auth.authorize(: | 
| 88 | 
            +
                      @auth.authorize(type: :unknown)
         | 
| 89 89 | 
             
                    }.to raise_error(ArgumentError)
         | 
| 90 90 | 
             
                  end
         | 
| 91 91 | 
             
                end
         | 
| 92 92 |  | 
| 93 93 | 
             
                it "builds a VkontakteApi::Client instance with the received token" do
         | 
| 94 | 
            -
                  client =  | 
| 94 | 
            +
                  client = double("VkontakteApi::Client instance")
         | 
| 95 95 | 
             
                  VkontakteApi::Client.should_receive(:new).with(@token).and_return(client)
         | 
| 96 96 | 
             
                  @auth.authorize.should == client
         | 
| 97 97 | 
             
                end
         | 
| @@ -2,11 +2,11 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe VkontakteApi::Client do
         | 
| 4 4 | 
             
              before(:each) do
         | 
| 5 | 
            -
                @user_id      =  | 
| 6 | 
            -
                @string_token =  | 
| 5 | 
            +
                @user_id      = double("User id")
         | 
| 6 | 
            +
                @string_token = double("Access token as a String")
         | 
| 7 7 | 
             
                @expires_at   = Time.now - 2 * 60 * 60 # 2.hours.ago
         | 
| 8 8 |  | 
| 9 | 
            -
                @oauth2_token =  | 
| 9 | 
            +
                @oauth2_token = double("Access token as an OAuth2::AccessToken")
         | 
| 10 10 | 
             
                @oauth2_token.stub(:token).and_return(@string_token)
         | 
| 11 11 | 
             
                @oauth2_token.stub(:params).and_return('user_id' => @user_id)
         | 
| 12 12 | 
             
                @oauth2_token.stub(:expires_at).and_return(@expires_at)
         | 
| @@ -3,20 +3,20 @@ require 'spec_helper' | |
| 3 3 | 
             
            describe VkontakteApi::Error do
         | 
| 4 4 | 
             
              before(:each) do
         | 
| 5 5 | 
             
                @error_data = Hashie::Mash.new(
         | 
| 6 | 
            -
                  : | 
| 7 | 
            -
                  : | 
| 8 | 
            -
                  : | 
| 6 | 
            +
                  error_code:     5,
         | 
| 7 | 
            +
                  error_msg:      'User authorization failed: invalid access_token.',
         | 
| 8 | 
            +
                  request_params: [
         | 
| 9 9 | 
             
                    {
         | 
| 10 | 
            -
                      : | 
| 11 | 
            -
                      : | 
| 10 | 
            +
                      key:   'oauth',
         | 
| 11 | 
            +
                      value: '1'
         | 
| 12 12 | 
             
                    },
         | 
| 13 13 | 
             
                    {
         | 
| 14 | 
            -
                      : | 
| 15 | 
            -
                      : | 
| 14 | 
            +
                      key:   'method',
         | 
| 15 | 
            +
                      value: 'unknownMethod'
         | 
| 16 16 | 
             
                    },
         | 
| 17 17 | 
             
                    {
         | 
| 18 | 
            -
                      : | 
| 19 | 
            -
                      : | 
| 18 | 
            +
                      key:   'access_token',
         | 
| 19 | 
            +
                      value: '123'
         | 
| 20 20 | 
             
                    }
         | 
| 21 21 | 
             
                  ]
         | 
| 22 22 | 
             
                )
         | 
| @@ -40,7 +40,7 @@ describe VkontakteApi::Error do | |
| 40 40 |  | 
| 41 41 | 
             
                context "with parameters" do
         | 
| 42 42 | 
             
                  before(:each) do
         | 
| 43 | 
            -
                    @error_data[:request_params] << Hashie::Mash.new(: | 
| 43 | 
            +
                    @error_data[:request_params] << Hashie::Mash.new(key: 'some', value: 'params')
         | 
| 44 44 | 
             
                    @e = VkontakteApi::Error.new(@error_data)
         | 
| 45 45 | 
             
                  end
         | 
| 46 46 |  | 
| @@ -5,11 +5,11 @@ describe VkontakteApi::Logger do | |
| 5 5 | 
             
                @success_response = Oj.dump('a' => 1, 'b' => 2)
         | 
| 6 6 | 
             
                @fail_response    = Oj.dump('error' => 404)
         | 
| 7 7 |  | 
| 8 | 
            -
                @connection = Faraday.new(: | 
| 8 | 
            +
                @connection = Faraday.new(url: 'http://example.com') do |builder|
         | 
| 9 9 | 
             
                  builder.request  :url_encoded
         | 
| 10 10 | 
             
                  builder.response :vk_logger
         | 
| 11 11 | 
             
                  builder.response :mashify
         | 
| 12 | 
            -
                  builder.response :oj, : | 
| 12 | 
            +
                  builder.response :oj, preserve_raw: true
         | 
| 13 13 |  | 
| 14 14 | 
             
                  builder.adapter :test do |stub|
         | 
| 15 15 | 
             
                    stub.get('/success') do
         | 
| @@ -24,7 +24,7 @@ describe VkontakteApi::Logger do | |
| 24 24 | 
             
                  end
         | 
| 25 25 | 
             
                end
         | 
| 26 26 |  | 
| 27 | 
            -
                @logger =  | 
| 27 | 
            +
                @logger = double("Logger").as_null_object
         | 
| 28 28 | 
             
                VkontakteApi.logger = @logger
         | 
| 29 29 |  | 
| 30 30 | 
             
                VkontakteApi.log_requests  = false
         | 
| @@ -46,7 +46,7 @@ describe VkontakteApi::Logger do | |
| 46 46 | 
             
                  it "logs the request URL and the request body" do
         | 
| 47 47 | 
             
                    @logger.should_receive(:debug).with('POST http://example.com/success')
         | 
| 48 48 | 
             
                    @logger.should_receive(:debug).with('body: "param=1"')
         | 
| 49 | 
            -
                    @connection.post('/success', : | 
| 49 | 
            +
                    @connection.post('/success', param: 1)
         | 
| 50 50 | 
             
                  end
         | 
| 51 51 | 
             
                end
         | 
| 52 52 | 
             
              end
         | 
| @@ -3,9 +3,9 @@ require 'spec_helper' | |
| 3 3 | 
             
            describe VkontakteApi::Method do
         | 
| 4 4 | 
             
              describe "#call" do
         | 
| 5 5 | 
             
                before(:each) do
         | 
| 6 | 
            -
                  @full_name =  | 
| 7 | 
            -
                  @args      =  | 
| 8 | 
            -
                  @token     =  | 
| 6 | 
            +
                  @full_name = double("Full method name")
         | 
| 7 | 
            +
                  @args      = double("Method arguments")
         | 
| 8 | 
            +
                  @token     = double("Access token")
         | 
| 9 9 |  | 
| 10 10 | 
             
                  @method = VkontakteApi::Method.new('some_name')
         | 
| 11 11 | 
             
                  @method.stub(:full_name).and_return(@full_name)
         | 
| @@ -19,9 +19,9 @@ describe VkontakteApi::Method do | |
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                it "sends the response to Result.process" do
         | 
| 22 | 
            -
                  response =  | 
| 22 | 
            +
                  response = double("VK response")
         | 
| 23 23 | 
             
                  VkontakteApi::API.stub(:call).and_return(response)
         | 
| 24 | 
            -
                  type =  | 
| 24 | 
            +
                  type = double("Type")
         | 
| 25 25 | 
             
                  @method.stub(:type).and_return(type)
         | 
| 26 26 |  | 
| 27 27 | 
             
                  VkontakteApi::Result.should_receive(:process).with(response, type, nil)
         | 
| @@ -31,9 +31,9 @@ describe VkontakteApi::Method do | |
| 31 31 |  | 
| 32 32 | 
             
              describe "#full_name" do
         | 
| 33 33 | 
             
                before(:each) do
         | 
| 34 | 
            -
                  resolver = Hashie::Mash.new(: | 
| 34 | 
            +
                  resolver = Hashie::Mash.new(name: 'name_space')
         | 
| 35 35 | 
             
                  @name = 'name'
         | 
| 36 | 
            -
                  @method = VkontakteApi::Method.new(@name, : | 
| 36 | 
            +
                  @method = VkontakteApi::Method.new(@name, resolver: resolver)
         | 
| 37 37 | 
             
                end
         | 
| 38 38 |  | 
| 39 39 | 
             
                it "sends each part to #camelize" do
         | 
| @@ -9,11 +9,11 @@ describe VkontakteApi::Resolvable do | |
| 9 9 |  | 
| 10 10 | 
             
              describe "#initialize" do
         | 
| 11 11 | 
             
                it "should save name and resolver" do
         | 
| 12 | 
            -
                  name     =  | 
| 13 | 
            -
                  token    =  | 
| 14 | 
            -
                  resolver = Hashie::Mash.new(: | 
| 12 | 
            +
                  name     = double("Name")
         | 
| 13 | 
            +
                  token    = double("Token")
         | 
| 14 | 
            +
                  resolver = Hashie::Mash.new(token: token)
         | 
| 15 15 |  | 
| 16 | 
            -
                  resolvable = @class.new(name, : | 
| 16 | 
            +
                  resolvable = @class.new(name, resolver: resolver)
         | 
| 17 17 | 
             
                  resolvable.name.should  == name
         | 
| 18 18 | 
             
                  resolvable.token.should == token
         | 
| 19 19 | 
             
                end
         | 
| @@ -14,7 +14,7 @@ describe VkontakteApi::Resolver do | |
| 14 14 | 
             
              describe "#method_missing" do
         | 
| 15 15 | 
             
                before(:each) do
         | 
| 16 16 | 
             
                  @resolver = @class.new(:trololo)
         | 
| 17 | 
            -
                  @token =  | 
| 17 | 
            +
                  @token = double("Token")
         | 
| 18 18 | 
             
                  @resolver.stub(:token).and_return(@token)
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| @@ -27,28 +27,42 @@ describe VkontakteApi::Resolver do | |
| 27 27 |  | 
| 28 28 | 
             
                context "called with a method" do
         | 
| 29 29 | 
             
                  before(:each) do
         | 
| 30 | 
            -
                    @result =  | 
| 31 | 
            -
                    @method =  | 
| 30 | 
            +
                    @result = double("Result")
         | 
| 31 | 
            +
                    @method = double("Method", call: @result)
         | 
| 32 32 | 
             
                    VkontakteApi::Method.stub(:new).and_return(@method)
         | 
| 33 33 | 
             
                  end
         | 
| 34 34 |  | 
| 35 35 | 
             
                  it "creates a Method instance" do
         | 
| 36 | 
            -
                    VkontakteApi::Method.should_receive(:new).with('get', : | 
| 37 | 
            -
                    @resolver.get(: | 
| 36 | 
            +
                    VkontakteApi::Method.should_receive(:new).with('get', resolver: @resolver.resolver)
         | 
| 37 | 
            +
                    @resolver.get(id: 1)
         | 
| 38 38 | 
             
                  end
         | 
| 39 39 |  | 
| 40 40 | 
             
                  it "calls Method#call and returns the result" do
         | 
| 41 | 
            -
                    @method.should_receive(:call).with(: | 
| 42 | 
            -
                    @resolver.get(: | 
| 41 | 
            +
                    @method.should_receive(:call).with(id: 1)
         | 
| 42 | 
            +
                    @resolver.get(id: 1).should == @result
         | 
| 43 43 | 
             
                  end
         | 
| 44 44 | 
             
                end
         | 
| 45 45 | 
             
              end
         | 
| 46 46 |  | 
| 47 | 
            +
              describe "#send" do
         | 
| 48 | 
            +
                before(:each) do
         | 
| 49 | 
            +
                  @resolver = @class.new('trololo')
         | 
| 50 | 
            +
                  @token = double("Token")
         | 
| 51 | 
            +
                  @resolver.stub(:token).and_return(@token)
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
                
         | 
| 54 | 
            +
                it "gets into #method_missing" do
         | 
| 55 | 
            +
                  method = double("Method", call: nil)
         | 
| 56 | 
            +
                  VkontakteApi::Method.should_receive(:new).with('send', resolver: @resolver.resolver).and_return(method)
         | 
| 57 | 
            +
                  @resolver.send(message: 'hello')
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
              
         | 
| 47 61 | 
             
              describe "#resolver" do
         | 
| 48 62 | 
             
                before(:each) do
         | 
| 49 | 
            -
                  @name     =  | 
| 63 | 
            +
                  @name     = double("Name")
         | 
| 50 64 | 
             
                  @resolver = @class.new(@name)
         | 
| 51 | 
            -
                  @token    =  | 
| 65 | 
            +
                  @token    = double("Token")
         | 
| 52 66 | 
             
                  @resolver.stub(:token).and_return(@token)
         | 
| 53 67 | 
             
                end
         | 
| 54 68 |  | 
| @@ -59,7 +73,7 @@ describe VkontakteApi::Resolver do | |
| 59 73 | 
             
                end
         | 
| 60 74 |  | 
| 61 75 | 
             
                it "caches the result" do
         | 
| 62 | 
            -
                  @mash =  | 
| 76 | 
            +
                  @mash = double("Mash", name: @name, token: @token)
         | 
| 63 77 | 
             
                  Hashie::Mash.should_receive(:new).once.and_return(@mash)
         | 
| 64 78 | 
             
                  5.times { @resolver.resolver }
         | 
| 65 79 | 
             
                end
         | 
| @@ -72,9 +86,9 @@ describe VkontakteApi::Resolver do | |
| 72 86 |  | 
| 73 87 | 
             
                context "on first call" do
         | 
| 74 88 | 
             
                  it "loads namespaces from a file" do
         | 
| 75 | 
            -
                    filename =  | 
| 89 | 
            +
                    filename = double("Filename")
         | 
| 76 90 | 
             
                    File.should_receive(:expand_path).and_return(filename)
         | 
| 77 | 
            -
                    namespaces =  | 
| 91 | 
            +
                    namespaces = double("Namespaces list")
         | 
| 78 92 | 
             
                    YAML.should_receive(:load_file).with(filename).and_return(namespaces)
         | 
| 79 93 |  | 
| 80 94 | 
             
                    VkontakteApi::Resolver.namespaces
         | 
| @@ -3,8 +3,8 @@ require 'spec_helper' | |
| 3 3 | 
             
            describe VkontakteApi::Result do
         | 
| 4 4 | 
             
              describe ".process" do
         | 
| 5 5 | 
             
                before(:each) do
         | 
| 6 | 
            -
                  @response =  | 
| 7 | 
            -
                  @result =  | 
| 6 | 
            +
                  @response = double("Response")
         | 
| 7 | 
            +
                  @result = double("Result")
         | 
| 8 8 | 
             
                  subject.stub(:extract_result).and_return(@result)
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| @@ -15,8 +15,8 @@ describe VkontakteApi::Result do | |
| 15 15 |  | 
| 16 16 | 
             
                context "with a non-enumerable result" do
         | 
| 17 17 | 
             
                  before(:each) do
         | 
| 18 | 
            -
                    @type =  | 
| 19 | 
            -
                    @typecasted_value =  | 
| 18 | 
            +
                    @type = double("Type")
         | 
| 19 | 
            +
                    @typecasted_value = double("Typecasted value")
         | 
| 20 20 | 
             
                    subject.stub(:typecast).and_return(@typecasted_value)
         | 
| 21 21 | 
             
                  end
         | 
| 22 22 |  | 
| @@ -27,7 +27,7 @@ describe VkontakteApi::Result do | |
| 27 27 |  | 
| 28 28 | 
             
                  context "when block_given?" do
         | 
| 29 29 | 
             
                    it "yields the #typecast-ed value and returns the result of the block" do
         | 
| 30 | 
            -
                      block_result =  | 
| 30 | 
            +
                      block_result = double("Block result")
         | 
| 31 31 | 
             
                      @typecasted_value.should_receive(:result_method).and_return(block_result)
         | 
| 32 32 | 
             
                      block = proc(&:result_method)
         | 
| 33 33 |  | 
| @@ -38,8 +38,8 @@ describe VkontakteApi::Result do | |
| 38 38 |  | 
| 39 39 | 
             
                context "with an enumerable result" do
         | 
| 40 40 | 
             
                  before(:each) do
         | 
| 41 | 
            -
                    @element1 =  | 
| 42 | 
            -
                    @element2 =  | 
| 41 | 
            +
                    @element1 = double("First element")
         | 
| 42 | 
            +
                    @element2 = double("Second element")
         | 
| 43 43 | 
             
                    @enumerable_result = [@element1, @element2]
         | 
| 44 44 | 
             
                    subject.stub(:extract_result).and_return(@enumerable_result)
         | 
| 45 45 | 
             
                  end
         | 
| @@ -50,8 +50,8 @@ describe VkontakteApi::Result do | |
| 50 50 |  | 
| 51 51 | 
             
                  context "when block_given?" do
         | 
| 52 52 | 
             
                    it "yields each element untouched to the block" do
         | 
| 53 | 
            -
                      result1 =  | 
| 54 | 
            -
                      result2 =  | 
| 53 | 
            +
                      result1 = double("First element after result_method")
         | 
| 54 | 
            +
                      result2 = double("Second element after result_method")
         | 
| 55 55 | 
             
                      @element1.should_receive(:result_method).and_return(result1)
         | 
| 56 56 | 
             
                      @element2.should_receive(:result_method).and_return(result2)
         | 
| 57 57 | 
             
                      block = proc(&:result_method)
         | 
| @@ -64,13 +64,13 @@ describe VkontakteApi::Result do | |
| 64 64 |  | 
| 65 65 | 
             
              describe ".extract_result" do
         | 
| 66 66 | 
             
                before(:each) do
         | 
| 67 | 
            -
                  @result_response  = {'key' => 'value'}
         | 
| 68 | 
            -
                  @result_error     = {'request_params' => [{'key' => 'error', 'value' => 'description'}]}
         | 
| 67 | 
            +
                  @result_response  = { 'key' => 'value' }
         | 
| 68 | 
            +
                  @result_error     = { 'request_params' => [{ 'key' => 'error', 'value' => 'description' }] }
         | 
| 69 69 | 
             
                end
         | 
| 70 70 |  | 
| 71 71 | 
             
                context "with a successful response" do
         | 
| 72 72 | 
             
                  before(:each) do
         | 
| 73 | 
            -
                    @result = Hashie::Mash.new(: | 
| 73 | 
            +
                    @result = Hashie::Mash.new(response: @result_response)
         | 
| 74 74 | 
             
                  end
         | 
| 75 75 |  | 
| 76 76 | 
             
                  it "returns the response part" do
         | 
| @@ -80,7 +80,7 @@ describe VkontakteApi::Result do | |
| 80 80 |  | 
| 81 81 | 
             
                context "with an error response" do
         | 
| 82 82 | 
             
                  before(:each) do
         | 
| 83 | 
            -
                    @result = Hashie::Mash.new(: | 
| 83 | 
            +
                    @result = Hashie::Mash.new(error: @result_error)
         | 
| 84 84 | 
             
                  end
         | 
| 85 85 |  | 
| 86 86 | 
             
                  it "raises a VkontakteApi::Error" do
         |