-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support stubbing of the ENV variable
- Loading branch information
Showing
7 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,11 @@ For constants: | |
- `const` for stubbed constant | ||
- `value` for a value of the constant | ||
|
||
For environment variables: | ||
|
||
- `env` for the name of a variable | ||
`value` for a value of the variable | ||
|
||
For http requests: | ||
|
||
- `url` or `uri` for the URI of the request (treats values like `/.../` as regular expressions) | ||
|
@@ -186,9 +191,14 @@ For http requests: | |
arguments: | ||
- "Profile with id: 1 not found" # for error message | ||
# Here we stubbing a constant | ||
- const: NOTIFIER_TIMEOUT_SEC | ||
value: 10 | ||
# This is a stub for ENV['DEFAULT_EMAIL'] | ||
- env: DEFAULT_EMAIL | ||
value: [email protected] | ||
# Examples for stubbing HTTP | ||
- uri: /example.com/foo/ # regexp! | ||
method: delete | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Fixturama::Changes | ||
# | ||
# @private | ||
# Stub an environment variable | ||
# | ||
class Env < Base | ||
# All changes has the same +key+ | ||
# They will be merged before stubbing (see +call+) | ||
def key | ||
"ENV" | ||
end | ||
|
||
# When we merge 2 env-s, we just merge their options | ||
def merge(other) | ||
return self unless other.is_a?(self.class) | ||
dup.tap { |env| env.options.update(other.options) } | ||
end | ||
|
||
def call(example) | ||
original = Hash ENV | ||
example.send(:stub_const, "ENV", original.merge(options)) | ||
self | ||
end | ||
|
||
protected | ||
|
||
attr_reader :options | ||
|
||
private | ||
|
||
def initialize(**options) | ||
@options = { options[:env].to_s => options[:value].to_s } | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module Fixturama | ||
# The current version of the gem | ||
VERSION = "0.3.0" | ||
end |
This file contains 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
This file contains 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