ghclient 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ require 'yaml'
2
+
3
+ module Helpers
4
+ module FixturesHelper
5
+
6
+ def read_fixture file
7
+ text = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", file))
8
+ YAML.load(text)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,116 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require './gh_client'
21
+ require 'vcr'
22
+ require 'webmock'
23
+ Dir.glob(File.dirname(__FILE__) + "/helpers/*.rb").each{|f| require_relative f}
24
+
25
+ RSpec.configure do |config|
26
+ # rspec-expectations config goes here. You can use an alternate
27
+ # assertion/expectation library such as wrong or the stdlib/minitest
28
+ # assertions if you prefer.
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+ end
39
+
40
+ config.include Helpers::FixturesHelper
41
+
42
+ # rspec-mocks config goes here. You can use an alternate test double
43
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
44
+ config.mock_with :rspec do |mocks|
45
+ # Prevents you from mocking or stubbing a method that does not exist on
46
+ # a real object. This is generally recommended, and will default to
47
+ # `true` in RSpec 4.
48
+ mocks.verify_partial_doubles = true
49
+ end
50
+
51
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
52
+ # have no way to turn it off -- the option exists only for backwards
53
+ # compatibility in RSpec 3). It causes shared context metadata to be
54
+ # inherited by the metadata hash of host groups and examples, rather than
55
+ # triggering implicit auto-inclusion in groups with matching metadata.
56
+ config.shared_context_metadata_behavior = :apply_to_host_groups
57
+
58
+ VCR.configure do |config|
59
+ config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
60
+ config.hook_into :webmock # or :fakeweb
61
+ end
62
+
63
+ # The settings below are suggested to provide a good initial experience
64
+ # with RSpec, but feel free to customize to your heart's content.
65
+ =begin
66
+ # This allows you to limit a spec run to individual examples or groups
67
+ # you care about by tagging them with `:focus` metadata. When nothing
68
+ # is tagged with `:focus`, all examples get run. RSpec also provides
69
+ # aliases for `it`, `describe`, and `context` that include `:focus`
70
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
71
+ config.filter_run_when_matching :focus
72
+
73
+ # Allows RSpec to persist some state between runs in order to support
74
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
75
+ # you configure your source control system to ignore this file.
76
+ config.example_status_persistence_file_path = "spec/examples.txt"
77
+
78
+ # Limits the available syntax to the non-monkey patched syntax that is
79
+ # recommended. For more details, see:
80
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
81
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
82
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
83
+ config.disable_monkey_patching!
84
+
85
+ # This setting enables warnings. It's recommended, but in some cases may
86
+ # be too noisy due to issues in dependencies.
87
+ config.warnings = true
88
+
89
+ # Many RSpec users commonly either run the entire suite or an individual
90
+ # file, and it's useful to allow more verbose output when running an
91
+ # individual spec file.
92
+ if config.files_to_run.one?
93
+ # Use the documentation formatter for detailed output,
94
+ # unless a formatter has already been configured
95
+ # (e.g. via a command-line flag).
96
+ config.default_formatter = 'doc'
97
+ end
98
+
99
+ # Print the 10 slowest examples and example groups at the
100
+ # end of the spec run, to help surface which specs are running
101
+ # particularly slow.
102
+ config.profile_examples = 10
103
+
104
+ # Run specs in random order to surface order dependencies. If you find an
105
+ # order dependency and want to debug it, you can fix the order by providing
106
+ # the seed, which is printed after each run.
107
+ # --seed 1234
108
+ config.order = :random
109
+
110
+ # Seed global randomization in this process using the `--seed` CLI option.
111
+ # Setting this allows you to use `--seed` to deterministically reproduce
112
+ # test failures related to randomization by passing the same `--seed` value
113
+ # as the one that triggered the failure.
114
+ Kernel.srand config.seed
115
+ =end
116
+ end
@@ -0,0 +1,26 @@
1
+ describe GHClient::Api do
2
+
3
+ it "should call get method with value /users/my_user" do
4
+ connection = instance_double("GHClient::Connection")
5
+ expect(connection).to receive(:get).with("/users/my_user")
6
+
7
+ api = GHClient::Api.new(connection)
8
+ api.get_user("my_user")
9
+ end
10
+
11
+ it "should call get method with value /users/my_user/repos" do
12
+ connection = instance_double("GHClient::Connection")
13
+ expect(connection).to receive(:get).with("/users/my_user/repos")
14
+
15
+ api = GHClient::Api.new(connection)
16
+ api.get_repositories("my_user")
17
+ end
18
+
19
+ it "should call get method with value /repos/my_user/my_repo/languages" do
20
+ connection = instance_double("GHClient::Connection")
21
+ expect(connection).to receive(:get).with("/repos/my_user/my_repo/languages")
22
+
23
+ api = GHClient::Api.new(connection)
24
+ api.get_languages_for_repository("my_user/my_repo")
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ describe GHClient::Cli do
2
+
3
+ context "with fake api" do
4
+ let(:cli) do
5
+ api = instance_double("GHClient::Api")
6
+ device = StringIO.new
7
+ GHClient::Cli.new(api: api, device: device)
8
+ end
9
+
10
+ it "should print_repo_info" do
11
+ cli.print_repo_info(
12
+ {"full_name" => "my_user/my_repo"},
13
+ {"Java" => 100, "Ruby" => 598} )
14
+
15
+ expected_text = read_fixture("cli.yml")
16
+
17
+ expect(cli.device.string).to eq( expected_text["repo_info"] )
18
+ end
19
+
20
+ it "should print_progress correctly for prolog" do
21
+ cli.print_progress(568, "Prolog", 311)
22
+
23
+ expected_text = read_fixture("cli.yml")
24
+
25
+ expect(cli.device.string).to eq( expected_text["print_progress"] )
26
+ end
27
+ end
28
+
29
+ it "should print correctly for user hermesdt" do
30
+ api = GHClient::Api.new
31
+ device = StringIO.new
32
+ cli = GHClient::Cli.new(api: api, device: device)
33
+
34
+ expected_text = read_fixture("cli.yml")
35
+
36
+ VCR.use_cassette("synopsis") do
37
+ cli.print_for_user("hermesdt")
38
+ expect(cli.device.string).to eq( expected_text["print_for_user"] )
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,22 @@
1
+ describe GHClient::Connection do
2
+ it "should have https://api.github.com as BASE_TOKEN constant" do
3
+ expect(GHClient::Connection::BASE_URL).to eq("https://api.github.com")
4
+ end
5
+
6
+ it "should raise an error becuase no access token is present" do
7
+ connection = GHClient::Connection::new
8
+
9
+ expect{
10
+ connection.check_options!({})
11
+ }.to raise_error(GHClient::NoAccessToken)
12
+ end
13
+
14
+ it "should save latest response" do
15
+ connection = GHClient::Connection::new
16
+
17
+ response = double(:response, body: {k: :v}.to_json)
18
+ connection.check_and_parse_response!(response)
19
+
20
+ expect(connection.last_response).to eq(response)
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ describe GHClient::Repository do
2
+
3
+ it "should return /users/my_user/repos" do
4
+ path = GHClient::Repository.languages_path("my_user/my_repo")
5
+ expect(path).to eq("/repos/my_user/my_repo/languages")
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ describe GHClient::User do
2
+
3
+ it "should return /users/my_user" do
4
+ path = GHClient::User.path("my_user")
5
+ expect(path).to eq("/users/my_user")
6
+ end
7
+
8
+ end
@@ -0,0 +1,5 @@
1
+ describe GHClient::User do
2
+ it "should be true" do
3
+ expect(true).to be(true)
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghclient
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alvaro Duran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ description:
56
+ email:
57
+ - hermesdt@gmail.com
58
+ executables:
59
+ - ghclient
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - bin/ghclient
64
+ - lib/ghclient.rb
65
+ - lib/ghclient/api.rb
66
+ - lib/ghclient/cli.rb
67
+ - lib/ghclient/connection.rb
68
+ - lib/ghclient/repository.rb
69
+ - lib/ghclient/user.rb
70
+ - spec/fixtures/cli.yml
71
+ - spec/fixtures/vcr_cassettes/synopsis.yml
72
+ - spec/helpers/fixtures_helper.rb
73
+ - spec/spec_helper.rb
74
+ - spec/unit/api_spec.rb
75
+ - spec/unit/ghclient/cli_spec.rb
76
+ - spec/unit/ghclient/connection_spec.rb
77
+ - spec/unit/ghclient/repository_spec.rb
78
+ - spec/unit/ghclient/user_spec.rb
79
+ - spec/unit/user_spec.rb
80
+ homepage: http://github.com/hermesdt/ghclient
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.5.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: github client
104
+ test_files:
105
+ - spec/fixtures/cli.yml
106
+ - spec/fixtures/vcr_cassettes/synopsis.yml
107
+ - spec/helpers/fixtures_helper.rb
108
+ - spec/spec_helper.rb
109
+ - spec/unit/api_spec.rb
110
+ - spec/unit/ghclient/cli_spec.rb
111
+ - spec/unit/ghclient/connection_spec.rb
112
+ - spec/unit/ghclient/repository_spec.rb
113
+ - spec/unit/ghclient/user_spec.rb
114
+ - spec/unit/user_spec.rb