From d185cfe576a634e04ecc1dd305a4f4fcd9bcadfb Mon Sep 17 00:00:00 2001 From: RemoteCTO <768254+RemoteCTO@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:38:21 +0000 Subject: [PATCH 1/2] Bring everything up to date and use async --- .rspec_status | 55 +++++------ .rubocop.yml | 26 ++--- .standard.yml | 5 + Gemfile | 20 ++-- Gemfile.lock | 147 +++++++++++++++++++--------- Rakefile | 6 +- bin/console | 6 +- lib/remoteok.rb | 4 +- lib/remoteok/client.rb | 28 +++--- lib/remoteok/job.rb | 46 ++++----- lib/remoteok/version.rb | 2 +- remoteok.gemspec | 36 ++++--- spec/remote_ok/client_spec.rb | 177 ++++++++++++++++++++++++++++++++++ spec/remote_ok/job_spec.rb | 113 ++++++++++++++++++++++ spec/remote_ok_spec.rb | 7 ++ spec/remoteok/client_spec.rb | 120 ----------------------- spec/remoteok/job_spec.rb | 113 ---------------------- spec/remoteok_spec.rb | 7 -- spec/spec_helper.rb | 6 +- 19 files changed, 514 insertions(+), 410 deletions(-) create mode 100644 .standard.yml create mode 100644 spec/remote_ok/client_spec.rb create mode 100644 spec/remote_ok/job_spec.rb create mode 100644 spec/remote_ok_spec.rb delete mode 100644 spec/remoteok/client_spec.rb delete mode 100644 spec/remoteok/job_spec.rb delete mode 100644 spec/remoteok_spec.rb diff --git a/.rspec_status b/.rspec_status index 0c27035..f0b6ade 100644 --- a/.rspec_status +++ b/.rspec_status @@ -1,30 +1,25 @@ -example_id | status | run_time | ---------------------------------------- | ------ | --------------- | -./spec/remoteok/client_spec.rb[1:1] | passed | 0.00902 seconds | -./spec/remoteok/client_spec.rb[1:2:1] | passed | 0.00061 seconds | -./spec/remoteok/client_spec.rb[1:2:2:1] | passed | 0.00042 seconds | -./spec/remoteok/client_spec.rb[1:3:1] | passed | 0.00042 seconds | -./spec/remoteok/client_spec.rb[1:4:1] | passed | 0.00128 seconds | -./spec/remoteok/client_spec.rb[1:4:2] | passed | 0.00042 seconds | -./spec/remoteok/client_spec.rb[1:5:1] | passed | 0.00096 seconds | -./spec/remoteok/client_spec.rb[1:5:2] | passed | 0.00124 seconds | -./spec/remoteok/client_spec.rb[1:5:3:1] | passed | 0.00045 seconds | -./spec/remoteok/client_spec.rb[1:5:4:1] | passed | 0.00058 seconds | -./spec/remoteok/job_spec.rb[1:1] | passed | 0.00041 seconds | -./spec/remoteok/job_spec.rb[1:2:1] | passed | 0.00019 seconds | -./spec/remoteok/job_spec.rb[1:3:1] | passed | 0.00019 seconds | -./spec/remoteok/job_spec.rb[1:4:1] | passed | 0.00019 seconds | -./spec/remoteok/job_spec.rb[1:5:1] | passed | 0.00019 seconds | -./spec/remoteok/job_spec.rb[1:6:1] | passed | 0.00066 seconds | -./spec/remoteok/job_spec.rb[1:7:1] | passed | 0.0002 seconds | -./spec/remoteok/job_spec.rb[1:8:1] | passed | 0.00031 seconds | -./spec/remoteok/job_spec.rb[1:9:1] | passed | 0.00027 seconds | -./spec/remoteok/job_spec.rb[1:10:1] | passed | 0.00023 seconds | -./spec/remoteok/job_spec.rb[1:11:1] | passed | 0.00028 seconds | -./spec/remoteok/job_spec.rb[1:12:1] | passed | 0.00024 seconds | -./spec/remoteok/job_spec.rb[1:13:1] | passed | 0.00035 seconds | -./spec/remoteok/job_spec.rb[1:14:1] | passed | 0.0003 seconds | -./spec/remoteok/job_spec.rb[1:15:1] | passed | 0.00032 seconds | -./spec/remoteok/job_spec.rb[1:16:1] | passed | 0.01251 seconds | -./spec/remoteok/job_spec.rb[1:17:1] | passed | 0.00037 seconds | -./spec/remoteok_spec.rb[1:1] | passed | 0.00017 seconds | +example_id | status | run_time | +-------------------------------------- | ------ | --------------- | +./spec/remote_ok/client_spec.rb[1:1] | passed | 0.00199 seconds | +./spec/remote_ok/client_spec.rb[1:2:1] | passed | 0.00056 seconds | +./spec/remote_ok/client_spec.rb[1:3:1] | passed | 0.00038 seconds | +./spec/remote_ok/client_spec.rb[1:3:2] | passed | 0.00075 seconds | +./spec/remote_ok/client_spec.rb[1:4:1] | passed | 0.00034 seconds | +./spec/remote_ok/job_spec.rb[1:1] | passed | 0.00007 seconds | +./spec/remote_ok/job_spec.rb[1:2:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:3:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:4:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:5:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:6:1] | passed | 0.00021 seconds | +./spec/remote_ok/job_spec.rb[1:7:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:8:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:9:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:10:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:11:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:12:1] | passed | 0.00022 seconds | +./spec/remote_ok/job_spec.rb[1:13:1] | passed | 0.00012 seconds | +./spec/remote_ok/job_spec.rb[1:14:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:15:1] | passed | 0.00019 seconds | +./spec/remote_ok/job_spec.rb[1:16:1] | passed | 0.00006 seconds | +./spec/remote_ok/job_spec.rb[1:17:1] | passed | 0.00006 seconds | +./spec/remote_ok_spec.rb[1:1] | passed | 0.00002 seconds | diff --git a/.rubocop.yml b/.rubocop.yml index d1bef68..20675a0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,20 +1,10 @@ -AllCops: - NewCops: enable - TargetRubyVersion: 2.6 - -Style/StringLiterals: - Enabled: true - EnforcedStyle: single_quotes +require: + - standard + - rubocop-rspec + - rubocop-performance -Style/StringLiteralsInInterpolation: - Enabled: true - EnforcedStyle: double_quotes +inherit_gem: + standard: config/base.yml -Layout/LineLength: - Max: 120 - -Metrics/BlockLength: - Exclude: - - 'Rakefile' - - '**/*.rake' - - 'spec/**/*.rb' +AllCops: + NewCops: enable diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..335074a --- /dev/null +++ b/.standard.yml @@ -0,0 +1,5 @@ +fix: false # default: false +parallel: false # default: false +format: progress # default: Standard::Formatter +default_ignores: true # default: true +#ruby_version: 3.4.1 # default: RUBY_VERSION diff --git a/Gemfile b/Gemfile index b4df978..2fb018a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,18 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in remoteok.gemspec gemspec -gem 'rake', '~> 13.0' - -gem 'rspec', '~> 3.0' - -gem 'rubocop', '~> 1.7' -gem 'rubocop-rake' -gem 'rubocop-rspec' +# Dev dependencies +group :development, :test do + gem "rake", "~> 13.2" + gem "rspec", "~> 3.13" + gem "rubocop", "~> 1.69" + gem "rubocop-rake" + gem "rubocop-rspec" + gem "rubocop-performance" + gem "simplecov", "< 0.21" + gem "standard", "~> 1.31" +end diff --git a/Gemfile.lock b/Gemfile.lock index 00ec061..038d882 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,77 +2,130 @@ PATH remote: . specs: remoteok (0.1.0) - httparty (~> 0.18.1) + async-http (~> 0.65) GEM remote: https://rubygems.org/ specs: ast (2.4.2) - diff-lcs (1.4.4) - docile (1.3.5) - httparty (0.18.1) - mime-types (~> 3.0) - multi_xml (>= 0.5.2) - json (2.5.1) - mime-types (3.3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2021.0225) - multi_xml (0.6.0) - parallel (1.20.1) - parser (3.0.1.1) + async (2.21.1) + console (~> 1.29) + fiber-annotation + io-event (~> 1.6, >= 1.6.5) + async-http (0.86.0) + async (>= 2.10.2) + async-pool (~> 0.9) + io-endpoint (~> 0.14) + io-stream (~> 0.6) + metrics (~> 0.12) + protocol-http (~> 0.43) + protocol-http1 (>= 0.28.1) + protocol-http2 (~> 0.22) + traces (~> 0.10) + async-pool (0.10.2) + async (>= 1.25) + traces + console (1.29.2) + fiber-annotation + fiber-local (~> 1.1) + json + diff-lcs (1.5.1) + docile (1.4.1) + fiber-annotation (0.2.0) + fiber-local (1.1.0) + fiber-storage + fiber-storage (1.0.0) + io-endpoint (0.14.0) + io-event (1.7.5) + io-stream (0.6.1) + json (2.9.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + metrics (0.12.1) + parallel (1.26.3) + parser (3.3.6.0) ast (~> 2.4.1) - rainbow (3.0.0) - rake (13.0.3) - regexp_parser (2.1.1) - rexml (3.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + racc + protocol-hpack (1.5.1) + protocol-http (0.47.1) + protocol-http1 (0.28.1) + protocol-http (~> 0.22) + protocol-http2 (0.22.0) + protocol-hpack (~> 1.4) + protocol-http (~> 0.18) + racc (1.8.1) + rainbow (3.1.1) + rake (13.2.1) + regexp_parser (2.10.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - rubocop (1.13.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + rubocop (1.69.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.2.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.5.0) - parser (>= 3.0.1.1) - rubocop-rake (0.5.1) - rubocop - rubocop-rspec (2.3.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.37.0) + parser (>= 3.3.1.0) + rubocop-performance (1.23.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-ast (>= 1.1.0) - ruby-progressbar (1.11.0) + rubocop-rspec (3.3.0) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) simplecov (0.17.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - unicode-display_width (2.0.0) + standard (1.43.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.69.1) + standard-custom (~> 1.0.0) + standard-performance (~> 1.6) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.6.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.23.0) + traces (0.14.1) + unicode-display_width (3.1.3) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) PLATFORMS + arm64-darwin-24 x86_64-darwin-19 DEPENDENCIES - rake (~> 13.0) + rake (~> 13.2) remoteok! - rspec (~> 3.0) - rubocop (~> 1.7) + rspec (~> 3.13) + rubocop (~> 1.69) + rubocop-performance rubocop-rake rubocop-rspec - simplecov (< 0.18) + simplecov (< 0.21) + standard (~> 1.31) BUNDLED WITH - 2.2.15 + 2.6.2 diff --git a/Rakefile b/Rakefile index 4964751..cca7175 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -require 'rubocop/rake_task' +require "rubocop/rake_task" RuboCop::RakeTask.new diff --git a/bin/console b/bin/console index 445fbdc..8025c93 100755 --- a/bin/console +++ b/bin/console @@ -1,8 +1,8 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'bundler/setup' -require 'remoteok' +require "bundler/setup" +require "remoteok" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -11,5 +11,5 @@ require 'remoteok' # require "pry" # Pry.start -require 'irb' +require "irb" IRB.start(__FILE__) diff --git a/lib/remoteok.rb b/lib/remoteok.rb index 7374505..6f4731c 100644 --- a/lib/remoteok.rb +++ b/lib/remoteok.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'remoteok/version' -require_relative 'remoteok/client' +require_relative "remoteok/version" +require_relative "remoteok/client" # Module to interact with the RemoteOK API module RemoteOK diff --git a/lib/remoteok/client.rb b/lib/remoteok/client.rb index 2b00635..4114d6e 100644 --- a/lib/remoteok/client.rb +++ b/lib/remoteok/client.rb @@ -3,24 +3,26 @@ module RemoteOK # Client class to interact with the API itself class Client - require 'json' - require 'httparty' - require_relative 'job' - - include HTTParty + require "json" + require "async/http/internet/instance" + require_relative "job" def initialize(**config) - @base_url = config[:base_url] || 'https://remoteok.io/api' + @base_url = config[:base_url] || "https://remoteok.io/api" @debug = config[:debug] || false @user_agent = config[:user_agent] || default_user_agent end def with_fetch(params = {}) - options = { headers: { 'User-Agent' => @user_agent } } - options[:query] = params if params&.any? - options[:debug_output] = $stdout if @debug + uri = URI(@base_url) + uri.query = URI.encode_www_form(params) if params&.any? + + headers = {"User-Agent" => @user_agent} - response = self.class.get @base_url, options + response = Sync do + internet = Async::HTTP::Internet.new + internet.get(uri, headers) + end @data = JSON.parse(response.body) self @@ -28,11 +30,11 @@ def with_fetch(params = {}) def legal with_fetch unless @data - @data.first['legal'] + @data.first["legal"] end def jobs(*tags) - options = { tags: stringify(tags) } if tags&.any? + options = {tags: stringify(tags)} if tags&.any? with_fetch options unless @data @@ -46,7 +48,7 @@ def jobs(*tags) def stringify(tags = []) return unless tags.any? - tags.map { |tag| tag.to_s.gsub('_', ' ') }.join ',' + tags.map { |tag| tag.to_s.tr("_", " ") }.join "," end def default_user_agent diff --git a/lib/remoteok/job.rb b/lib/remoteok/job.rb index 0a31f6a..624fb42 100644 --- a/lib/remoteok/job.rb +++ b/lib/remoteok/job.rb @@ -3,86 +3,86 @@ module RemoteOK # Class representing a single job from RemoteOK with data accessors. class Job - require 'date' + require "date" attr_reader :raw - HTML_CHARS_REGEX = /<("[^"]*"|'[^']*'|[^'">])*>/.freeze + HTML_CHARS_REGEX = /<("[^"]*"|'[^']*'|[^'">])*>/ def initialize(job_data) @raw = job_data end def slug - raw['slug'] + raw["slug"] end def id - return unless raw['id'] + return unless raw["id"] - Integer raw['id'] + Integer raw["id"] end def epoch - return unless raw['epoch'] + return unless raw["epoch"] - Integer raw['epoch'] + Integer raw["epoch"] end def date - return unless raw['date'] + return unless raw["date"] - DateTime.parse raw['date'] + DateTime.parse raw["date"] end def company - raw['company'] + raw["company"] end def company_logo - raw['company_logo'] + raw["company_logo"] end def position - raw['position'] + raw["position"] end def tags - return unless raw['tags'] + return unless raw["tags"] - raw['tags'].map do |tag| - tag.gsub(' ', '_').to_sym + raw["tags"].map do |tag| + tag.tr(" ", "_").to_sym end end def logo - raw['logo'] + raw["logo"] end def description - raw['description'] + raw["description"] end def description_text - return unless raw['description'] + return unless raw["description"] - raw['description'].gsub(HTML_CHARS_REGEX, ' ').strip.gsub(/\s+/, ' ') + raw["description"].gsub(HTML_CHARS_REGEX, " ").strip.gsub(/\s+/, " ") end def location - raw['location'] + raw["location"] end def original - raw['original'] + raw["original"] end def url - raw['url'] + raw["url"] end def apply_url - raw['apply_url'] + raw["apply_url"] end end end diff --git a/lib/remoteok/version.rb b/lib/remoteok/version.rb index b234400..4fbd25c 100644 --- a/lib/remoteok/version.rb +++ b/lib/remoteok/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RemoteOK - VERSION = '0.1.0' + VERSION = "0.1.0" end diff --git a/remoteok.gemspec b/remoteok.gemspec index 78bf759..8d05191 100644 --- a/remoteok.gemspec +++ b/remoteok.gemspec @@ -1,23 +1,23 @@ # frozen_string_literal: true -require_relative 'lib/remoteok/version' +require_relative "lib/remoteok/version" Gem::Specification.new do |spec| - spec.name = 'remoteok' - spec.version = RemoteOK::VERSION - spec.authors = ['Edward Woodcock'] - spec.email = ['768254+RemoteCTO@users.noreply.github.com'] + spec.name = "remoteok" + spec.version = RemoteOK::VERSION + spec.authors = ["Edward Woodcock"] + spec.email = ["768254+RemoteCTO@users.noreply.github.com"] - spec.summary = 'Ruby client for RemoteOK Jobs API' - spec.description = 'Fetch data from the API at remoteok.io' - spec.homepage = 'https://github.com/RemoteCTO/remote-ok-ruby' - spec.license = 'MIT' - spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0') + spec.summary = "Ruby client for RemoteOK Jobs API" + spec.description = "Fetch data from the API at remoteok.io" + spec.homepage = "https://github.com/RemoteCTO/remote-ok-ruby" + spec.license = "MIT" + spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0") # spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com'' - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/RemoteCTO/remote-ok-ruby' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/RemoteCTO/remote-ok-ruby" # spec.metadata['changelog_uri'] = 'TODO: Put your gem's CHANGELOG.md URL here.' # Specify which files should be added to the gem when it is released. @@ -25,16 +25,14 @@ Gem::Specification.new do |spec| spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } end - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] # Prod dependencies - spec.add_dependency 'httparty', '~> 0.18.1' - - # Dev dependencies - spec.add_development_dependency 'simplecov', '< 0.18' + spec.add_dependency "async-http", "~> 0.65" # For more information and examples about making a new gem, checkout our # guide at: https://bundler.io/guides/creating_gem.html + spec.metadata["rubygems_mfa_required"] = "true" end diff --git a/spec/remote_ok/client_spec.rb b/spec/remote_ok/client_spec.rb new file mode 100644 index 0000000..6a7c184 --- /dev/null +++ b/spec/remote_ok/client_spec.rb @@ -0,0 +1,177 @@ +# frozen_string_literal: true + +RSpec.describe RemoteOK::Client do + let(:job_data) { File.read("spec/fixtures/jobs_data.json") } + let(:http_response) { instance_double(Async::HTTP::Protocol::Response, body: job_data) } + let(:internet) { instance_double(Async::HTTP::Internet) } + let(:client) { described_class.new } + + before do + allow(Async::HTTP::Internet).to receive(:new).and_return(internet) + allow(internet).to receive(:get).and_return(http_response) + end + + it "can instantiate" do + expect(described_class.new).not_to be_nil + end + + describe "User Agent" do + before { client.with_fetch } + + let(:user_agent) do + "remote-ok-ruby/#{RemoteOK::VERSION} " \ + "+http://github.com/RemoteCTO/remote-ok-ruby" + end + + it "sends a default user agent with each request" do + expect(internet).to have_received(:get).with( + instance_of(URI::HTTPS), + hash_including("User-Agent" => user_agent) + ) + end + end + + # rubocop:disable RSpec/MultipleExpectations + describe "Jobs" do + let(:data) { File.read("spec/fixtures/jobs_data.json") } + + before { client.jobs(:ruby, :digital_nomad) } + + it "uses https" do + expect(internet).to have_received(:get) do |uri, headers| + expect(uri).to be_a(URI::HTTPS) + end + end + + it "provides the tags as parameters to the api" do + expect(internet).to have_received(:get) do |uri, headers| + expect(uri.query).to include("tags=ruby%2Cdigital+nomad") + end + end + end + # rubocop:enable RSpec/MultipleExpectations + + describe "Legal" do + it "fetches legal information" do + legal_info = client.legal + + expect(legal_info).to eq(JSON.parse(job_data).first["legal"]) + end + end + # let(:job_data) { File.open "spec/fixtures/jobs_data.json" } + + # before do + # instance_double("HTTParty", body: job_data.read) + # allow(described_class).to receive(:get).and_return(httpclient) + # end + + # it "can instantiate" do + # expect(described_class.new).not_to be_nil + # end + + # describe "User Agent" do + # it "sends a default user agent with each request" do + # httpclient = double("HTTParty", body: "{}") + # exp_params = { + # headers: { + # "User-Agent" => + # "remote-ok-ruby/0.1.0 +http://github.com/RemoteCTO/remote-ok-ruby" + # } + # } + + # expect(described_class).to( + # receive(:get) + # .with(anything, exp_params) + # .and_return(httpclient) + # ) + + # described_class.new.jobs + # end + + # context "when providing a custom user agent" do + # it "sends the custom user agent instead of the default" do + # httpclient = double("HTTParty", body: "{}") + # exp_params = {headers: {"User-Agent" => "lovely-user-agent"}} + + # expect(described_class).to( + # receive(:get) + # .with(anything, exp_params) + # .and_return(httpclient) + # ) + + # described_class.new(user_agent: "lovely-user-agent").jobs + # end + # end + # end + + # context "Debug flag on" do + # it "Requests HTTP debug output into the console" do + # httpclient = double("HTTParty", body: "{}") + # exp_params = { + # headers: {"User-Agent" => ""}, + # debug_output: $stdout + # } + + # expect(described_class).to( + # receive(:get) + # .with(anything, exp_params) + # .and_return(httpclient) + # ) + + # described_class.new(user_agent: "", debug: true).jobs + # end + # end + + # describe "legal" do + # it "outputs the RemoteOK legal text" do + # expect(described_class.new.legal).to start_with "API Terms of Service" + # end + + # it "can be chained with fetch to force refresh" do + # expect(described_class.new.with_fetch.legal).to start_with "API Terms of Service" + # end + # end + + # describe "jobs" do + # it "returns the correct number of items" do + # expect(described_class.new.jobs.size).to eq 3 + # end + + # it "returns an array of Job objects" do + # expect(described_class.new.jobs.first).to be_a RemoteOK::Job + # end + + # context "when there are no jobs" do + # before do + # nj_data = File.open "spec/fixtures/no_jobs.json" + # httpclient = double("HTTParty", body: nj_data.read) + # allow(described_class).to receive(:get).and_return(httpclient) + # end + + # it "returns zero jobs" do + # expect(described_class.new.jobs.size).to eq 0 + # end + # end + + # context "when providing tags" do + # let(:data) { File.open "spec/fixtures/jobs_data.json" } + # let(:http_client) { double("HTTParty", body: data.read) } + + # it "provides the tags as parameters to the api" do + # httpclient = double("HTTParty", body: data.read) + # exp_params = { + # headers: {"User-Agent" => ""}, + # query: {tags: "ruby,digital nomad"} + # } + + # expect(described_class).to( + # receive(:get) + # .with(anything, exp_params) + # .and_return(httpclient) + # ) + + # described_class.new(user_agent: "").jobs :ruby, :digital_nomad + # end + # end + # end +end diff --git a/spec/remote_ok/job_spec.rb b/spec/remote_ok/job_spec.rb new file mode 100644 index 0000000..d50c427 --- /dev/null +++ b/spec/remote_ok/job_spec.rb @@ -0,0 +1,113 @@ +# frozen_string_literal: true + +RSpec.describe RemoteOK::Job do + let(:job_data) do + file = File.open "spec/fixtures/jobs_data.json" + JSON.parse(file.read).last + end + + let(:job) do + described_class.new(job_data) + end + + it "can instantiate" do + expect(job).not_to be_nil + end + + describe "#raw" do + it "returns the original raw data" do + expect(job.raw).to eq job_data + end + end + + describe "#slug" do + it "returns the slug field" do + expect(job.slug).to eq "564738-remote-customer-success-associate" + end + end + + describe "#id" do + it "returns the id as an integer" do + expect(job.id).to eq 564_738 + end + end + + describe "#epoch" do + it "returns the epoch as an integer" do + expect(job.epoch).to eq 1_619_724_426 + end + end + + describe "#date" do + it "returns the date as a date" do + expect(job.date).to eq DateTime.new(2021, 4, 29, 19, 27, 6, "06+00:00") + end + end + + describe "#company" do + it "returns the company name" do + expect(job.company).to eq "Distance" + end + end + + describe "#company_logo" do + it "returns the company logo url as a string" do + expect(job.company_logo).to eq "https://remoteOK.io/assets/jobs/4b011439d2f3d8sa9das0710ff49c21619724426.png" + end + end + + describe "#position" do + it "returns the company position" do + expect(job.position).to eq "Customer Success Associate" + end + end + + describe "#tags" do + it "returns the array of tags" do + expect(job.tags).to eq %i[dev dot_net digital_nomad] + end + end + + describe "#logo" do + it "returns url for logo" do + expect(job.logo).to eq "https://remoteOK.io/assets/jobs/4b011439d2df9s8f0d9sff49c21619724426.png" + end + end + + describe "#description" do + it "returns the raw description" do + expect(job.description).to start_with "
Our Products" + end + end + + describe "#description_text" do + it "returns the raw description text with no html" do + substring = "Our Products Our software products involve industrial plant" + expect(job.description_text).to start_with substring + end + end + + describe "#location" do + it "returns the location string" do + expect(job.location).to eq "North America" + end + end + + describe "#original" do + it "returns the original flag" do + expect(job.original).to be true + end + end + + describe "#url" do + it "returns the url string" do + expect(job.url).to eq "https://remoteOK.io/remote-jobs/564738-remote-customer-success-associate" + end + end + + describe "#apply_url" do + it "returns the apply url string" do + expect(job.apply_url).to eq "https://remoteOK.io/l/564738" + end + end +end diff --git a/spec/remote_ok_spec.rb b/spec/remote_ok_spec.rb new file mode 100644 index 0000000..cba9260 --- /dev/null +++ b/spec/remote_ok_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +RSpec.describe RemoteOK do + it "has a version number" do + expect(RemoteOK::VERSION).not_to be_nil + end +end diff --git a/spec/remoteok/client_spec.rb b/spec/remoteok/client_spec.rb deleted file mode 100644 index 5bd7234..0000000 --- a/spec/remoteok/client_spec.rb +++ /dev/null @@ -1,120 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe RemoteOK::Client do - let(:job_data) { File.open 'spec/fixtures/jobs_data.json' } - - before do - httpclient = double('HTTParty', body: job_data.read) - allow(RemoteOK::Client).to receive(:get).and_return(httpclient) - end - - it 'can instantiate' do - expect(RemoteOK::Client.new).not_to be nil - end - - describe 'User Agent' do - it 'sends a default user agent with each request' do - httpclient = double('HTTParty', body: '{}') - exp_params = { - headers: { - 'User-Agent' => - 'remote-ok-ruby/0.1.0 +http://github.com/RemoteCTO/remote-ok-ruby' - } - } - - expect(RemoteOK::Client).to( - receive(:get) - .with(anything, exp_params) - .and_return(httpclient) - ) - - RemoteOK::Client.new.jobs - end - - context 'when providing a custom user agent' do - it 'sends the custom user agent instead of the default' do - httpclient = double('HTTParty', body: '{}') - exp_params = { headers: { 'User-Agent' => 'lovely-user-agent' } } - - expect(RemoteOK::Client).to( - receive(:get) - .with(anything, exp_params) - .and_return(httpclient) - ) - - RemoteOK::Client.new(user_agent: 'lovely-user-agent').jobs - end - end - end - - context 'Debug flag on' do - it 'Requests HTTP debug output into the console' do - httpclient = double('HTTParty', body: '{}') - exp_params = { - headers: { 'User-Agent' => '' }, - debug_output: $stdout - } - - expect(RemoteOK::Client).to( - receive(:get) - .with(anything, exp_params) - .and_return(httpclient) - ) - - RemoteOK::Client.new(user_agent: '', debug: true).jobs - end - end - - describe 'legal' do - it 'outputs the RemoteOK legal text' do - expect(RemoteOK::Client.new.legal).to start_with 'API Terms of Service' - end - - it 'can be chained with fetch to force refresh' do - expect(RemoteOK::Client.new.with_fetch.legal).to start_with 'API Terms of Service' - end - end - - describe 'jobs' do - it 'returns the correct number of items' do - expect(RemoteOK::Client.new.jobs.size).to eq 3 - end - - it 'returns an array of Job objects' do - expect(RemoteOK::Client.new.jobs.first).to be_a RemoteOK::Job - end - - context 'when there are no jobs' do - before do - nj_data = File.open 'spec/fixtures/no_jobs.json' - httpclient = double('HTTParty', body: nj_data.read) - allow(RemoteOK::Client).to receive(:get).and_return(httpclient) - end - - it 'returns zero jobs' do - expect(RemoteOK::Client.new.jobs.size).to eq 0 - end - end - - context 'when providing tags' do - let(:data) { File.open 'spec/fixtures/jobs_data.json' } - let(:http_client) { double('HTTParty', body: data.read) } - - it 'provides the tags as parameters to the api' do - httpclient = double('HTTParty', body: data.read) - exp_params = { - headers: { 'User-Agent' => '' }, - query: { tags: 'ruby,digital nomad' } - } - - expect(RemoteOK::Client).to( - receive(:get) - .with(anything, exp_params) - .and_return(httpclient) - ) - - RemoteOK::Client.new(user_agent: '').jobs :ruby, :digital_nomad - end - end - end -end diff --git a/spec/remoteok/job_spec.rb b/spec/remoteok/job_spec.rb deleted file mode 100644 index 4ac1c0e..0000000 --- a/spec/remoteok/job_spec.rb +++ /dev/null @@ -1,113 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe RemoteOK::Job do - let(:job_data) do - file = File.open 'spec/fixtures/jobs_data.json' - JSON.parse(file.read).last - end - - let(:job) do - RemoteOK::Job.new(job_data) - end - - it 'can instantiate' do - expect(job).not_to be nil - end - - describe '#raw' do - it 'returns the original raw data' do - expect(job.raw).to eq job_data - end - end - - describe '#slug' do - it 'returns the slug field' do - expect(job.slug).to eq '564738-remote-customer-success-associate' - end - end - - describe '#id' do - it 'returns the id as an integer' do - expect(job.id).to eq 564_738 - end - end - - describe '#epoch' do - it 'returns the epoch as an integer' do - expect(job.epoch).to eq 1_619_724_426 - end - end - - describe '#date' do - it 'returns the date as a date' do - expect(job.date).to eq DateTime.new(2021, 4, 29, 19, 27, 6, '06+00:00') - end - end - - describe '#company' do - it 'returns the company name' do - expect(job.company).to eq 'Distance' - end - end - - describe '#company_logo' do - it 'returns the company logo url as a string' do - expect(job.company_logo).to eq 'https://remoteOK.io/assets/jobs/4b011439d2f3d8sa9das0710ff49c21619724426.png' - end - end - - describe '#position' do - it 'returns the company position' do - expect(job.position).to eq 'Customer Success Associate' - end - end - - describe '#tags' do - it 'returns the array of tags' do - expect(job.tags).to eq %i[dev dot_net digital_nomad] - end - end - - describe '#logo' do - it 'returns url for logo' do - expect(job.logo).to eq 'https://remoteOK.io/assets/jobs/4b011439d2df9s8f0d9sff49c21619724426.png' - end - end - - describe '#description' do - it 'returns the raw description' do - expect(job.description).to start_with '
Our Products' - end - end - - describe '#description_text' do - it 'returns the raw description text with no html' do - substring = 'Our Products Our software products involve industrial plant' - expect(job.description_text).to start_with substring - end - end - - describe '#location' do - it 'returns the location string' do - expect(job.location).to eq 'North America' - end - end - - describe '#original' do - it 'returns the original flag' do - expect(job.original).to eq true - end - end - - describe '#url' do - it 'returns the url string' do - expect(job.url).to eq "https:\/\/remoteOK.io\/remote-jobs\/564738-remote-customer-success-associate" - end - end - - describe '#apply_url' do - it 'returns the apply url string' do - expect(job.apply_url).to eq "https:\/\/remoteOK.io\/l\/564738" - end - end -end diff --git a/spec/remoteok_spec.rb b/spec/remoteok_spec.rb deleted file mode 100644 index 8f9fb28..0000000 --- a/spec/remoteok_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe RemoteOK do - it 'has a version number' do - expect(RemoteOK::VERSION).not_to be nil - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 08e76a3..97575c4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'simplecov' +require "simplecov" SimpleCov.start -require 'remoteok' +require "remoteok" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! From e71bfa7c9ad5db111506790ce8245e28c0934f11 Mon Sep 17 00:00:00 2001 From: RemoteCTO <768254+RemoteCTO@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:44:34 +0000 Subject: [PATCH 2/2] Update gh workflow --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a985e47..ee8414a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,9 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.1 + ruby-version: 3.4.1 - name: Run the default task run: | - gem install bundler -v 2.2.15 + gem install bundler -v 2.6.2 bundle install bundle exec rake