Skip to content

Commit

Permalink
entry point for gem usage
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Feb 28, 2024
1 parent fd29638 commit d1e5ddc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/plants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,30 @@
require "plants/version"

module Plants
class << self

# @param new_value [String]
# @return [void]
def token=(new_value)
client.config.token = new_value
end

# @return [Plants::Config]
def config
client.config
end

# GET /plants
# @return [HTTP::Response]
def plants
client.plants
end

private

# @return [Plants::Client]
def client
@_client ||= Client.new
end
end
end
33 changes: 33 additions & 0 deletions spec/plants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,37 @@
it "has a version number" do
expect(Plants::VERSION).not_to be nil
end

describe '.token=' do
after(:each) { Plants.token = nil }

subject { Plants.token = 'secret' }

it do
subject
expect(Plants.config.token).to eql 'secret'
end
end

describe '.config' do
subject { Plants.config }

it do
expect(subject).to be_instance_of(Plants::Config)
end
end

describe '.plants' do
before(:each) do
stub_request(:get, "#{Plants::Client::URL}/plants")
.to_return(status: 200, body: '{}')
end

subject { Plants.plants }

it do
expect(subject).to be_instance_of(HTTP::Response)
expect(a_request(:get, "#{Plants::Client::URL}/plants")).to have_been_made
end
end
end

0 comments on commit d1e5ddc

Please sign in to comment.