Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoloadability via Bundler.require #137

Merged
merged 3 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/launchdarkly-server-sdk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative "ldclient-rb"
23 changes: 23 additions & 0 deletions spec/launchdarkly-server-sdk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "spec_helper"
require "bundler"

describe LaunchDarkly do
it "can be automatically loaded by Bundler.require" do
ldclient_loaded =
Bundler.with_clean_env do
Kernel.system("ruby", "-e", <<~RUBY)
require "bundler/setup"
require "bundler/inline"

gemfile do
gem "launchdarkly-server-sdk", path: "."
end

Bundler.require(:development)
abort unless $LOADED_FEATURES.any?(/ldclient-rb\.rb/)
RUBY
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this test mechanism is going to work in every version of Ruby that we support. It may need to be conditionally executed. Our CI build runs the tests in all supported versions, but it doesn't run on branches of forks.

What version(s) have you tested in?

Copy link
Contributor Author

@tonyta tonyta Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't quite work with Ruby < 2.5.0 because a pattern argument is passed to Enumerable#any? instead of a block. I'll change this example to ensure it can be run in earlier versions of Ruby.

Edit: I've made changes to ensure this works with Ruby versions 2.3, 2.4, 2.5, 2.6, and 2.7.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied your branch into a branch of our private mirror so I could run our own CI (I do think we will enable it for forks as you suggested, but in the meantime this is pretty easy for me to do). It's fine for 2.3-2.7, but we also support 2.2 and it doesn't work there because of the heredoc usage (<<~RUBY).

You could build a multi-line string in other ways, but it might be simpler to just break out the test script into a separate file, like launchdarkly-server-sdk_spec_autoloadtest.rb, and then have the test just do Kernel.system("ruby", "./spec/launchdarkly-server-sdk_spec_autoloadtest.rb"). I verified that this works in all of our supported versions (including JRuby).


expect(ldclient_loaded).to be true
end
end