Sha256: 97e8806df9f20bd1e8194bec8c7ef790472b9b4a25d10b030d75d49596f6d6aa
Contents?: true
Size: 1.77 KB
Versions: 2
Compression:
Stored size: 1.77 KB
Contents
module Helpers def underscore(s) s.to_s.scan(/[A-Z][a-z]*/).join("_").downcase end def camelize(s) s[0] + s.to_s.split("_").each {|s| s.capitalize! }.join("")[1..-1] end def load_fixture(subject, version, method='get') fixture_file = File.join(SPEC_ROOT, 'fixtures', "#{version}", "#{method}-#{subject}.json") JSON.parse(File.read(fixture_file, :encoding => "utf-8")) end def expect_init_attribute(subject, attribute) expect(subject.new(camelize(attribute) => "foo").send(attribute)).to eq("foo") end def expect_read_only_attribute(subject, attribute) expect { subject.new.send("#{attribute}=".to_sym, "bar") }.to raise_error(NoMethodError) end def error_401 response = {"status" => {"message" => "Foo", "status_code" => 401}} response.send :instance_eval do def code; 401; end def not_found?; false; end end response end def error_429 response = {"status" => {"message" => "Foo", "status_code" => 429}} response.send :instance_eval do def code; 429; end def not_found?; false; end end response end def summoners { "euw" => "30743211", "na" => "5908", "eune" => "35778105" } end def stub_request(request_object, fixture_name, url, params={}) request_class = request_object.class full_url = request_object.api_url(url, params) fixture_json = load_fixture(fixture_name, request_class.api_version, :get) expect(request_class).to receive(:get).with(full_url).and_return(fixture_json) end def stub_request_raw(request_object, raw_response, url, params={}) request_class = request_object.class full_url = request_object.api_url(url, params) expect(request_class).to receive(:get).with(full_url).and_return(raw_response) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ruby-lol-0.12.1 | spec/support/helpers.rb |
ruby-lol-0.12.0 | spec/support/helpers.rb |