Created
January 19, 2011 13:55
-
-
Save keithrbennett/786190 to your computer and use it in GitHub Desktop.
Tests the requiring of gem code not as gems, but regular file system files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Tests the requiring of gem code not as gems, but regular | |
| # file system files. | |
| # As an example, we can use this gem, change this to suit your system: | |
| JSON_REQUIRE_SPEC='/Users/kbennett/.rvm/gems/ree-1.8.7-2010.02/gems/json-1.4.6/lib/json' | |
| # Will change dir to the gem's directory before requiring it, | |
| # and change dir back to original directory when done. | |
| def require_expanded_gem(require_spec) | |
| dir = File.dirname(require_spec) | |
| Dir.chdir(dir) do | |
| puts "Contents of #{dir} are:\n\n#{Dir["#{dir}/*"].join("\n")}\n" # check the directory | |
| require require_spec | |
| end | |
| end | |
| # Now we call require_expanded_gem instead of require: | |
| require_expanded_gem JSON_REQUIRE_SPEC | |
| # ...and do something with JSON to verify that it loaded ok: | |
| p JSON.methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment