jenkins-bot has submitted this change and it was merged.
Change subject: Environment user and password methods
......................................................................
Environment user and password methods
Implemented methods for retrieving the mediawiki user and password from
the current environment context.
Support for `:mediawiki_password_variable`.
Fixed bugs in Environment#lookup and implemented missing specs.
Aliased PageFactory#on_page to #on.
Change-Id: I58b105d36919c251b1ecf28ba21a539f61d03dbc
---
M lib/mediawiki_selenium/environment.rb
M lib/mediawiki_selenium/page_factory.rb
M lib/mediawiki_selenium/support/hooks.rb
M spec/environment_spec.rb
4 files changed, 86 insertions(+), 15 deletions(-)
Approvals:
Dduvall: Looks good to me, approved
Hashar: Looks good to me, but someone else must approve
Zfilipin: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/lib/mediawiki_selenium/environment.rb
b/lib/mediawiki_selenium/environment.rb
index eb6848e..f5bb0a6 100644
--- a/lib/mediawiki_selenium/environment.rb
+++ b/lib/mediawiki_selenium/environment.rb
@@ -1,8 +1,8 @@
module MediawikiSelenium
# Provides an interface that unifies environmental configuration, page
- # objects, and browser setup. Additionally, it provides grammars for
- # switching between user/wiki/browser contexts in ways that help promote
- # decouple test implementation.
+ # objects, and browser setup. Additionally, it provides a DSL for switching
+ # between user/wiki/browser contexts in ways that help to decouple test
+ # implementation from the target wikis.
#
class Environment
include Comparable
@@ -62,7 +62,7 @@
# @return [Environment]
#
def as_user(id, &blk)
- with_alternative([:mediawiki_user, :mediawiki_password], id, &blk)
+ with_alternative([:mediawiki_user, password_variable], id, &blk)
end
# Browser with which to drive tests.
@@ -165,14 +165,14 @@
# @return [String]
#
def lookup(key, id = nil)
- key = "#{key}_#{id}" unless id.nil?
- key = key.to_sym
- value = @config[key]
+ full_key = id.nil? ? key : "#{key}_#{id}"
+ full_key = full_key.to_sym
+ value = @config[full_key]
if value.nil? || value.to_s.empty?
if id.nil?
- if REQUIRED_CONFIG.include?(key)
- raise ConfigurationError, key
+ if REQUIRED_CONFIG.include?(full_key)
+ raise ConfigurationError, full_key
else
nil
end
@@ -216,6 +216,17 @@
with_alternative([:mediawiki_url, :mediawiki_api_url], id, &blk)
end
+ # Returns the current value for `:mediawiki_password` or the value for the
+ # given alternative.
+ #
+ # @param id [Symbol] Alternative user ID.
+ #
+ # @return [String]
+ #
+ def password(id = nil)
+ lookup(password_variable, id)
+ end
+
# Whether this environment has been configured to use remote browser
# sessions.
#
@@ -256,6 +267,17 @@
else
scenario.name
end
+ end
+
+ # Returns the current value for `:mediawiki_user` or the value for the
+ # given alternative.
+ #
+ # @param id [Symbol] Alternative user ID.
+ #
+ # @return [String]
+ #
+ def user(id = nil)
+ lookup(:mediawiki_user, id)
end
# Navigates the current browser to the given wiki.
@@ -339,6 +361,11 @@
lookup_all(browser_factory.all_binding_keys)
end
+ def password_variable
+ name = lookup(:mediawiki_password_variable)
+ (name.nil? || name.empty?) ? :mediawiki_password : name.to_sym
+ end
+
def normalize_config(hash)
hash.each.with_object({}) { |(k, v), acc| acc[k.to_s.downcase.to_sym] =
v }
end
diff --git a/lib/mediawiki_selenium/page_factory.rb
b/lib/mediawiki_selenium/page_factory.rb
index 8da747f..ea66068 100644
--- a/lib/mediawiki_selenium/page_factory.rb
+++ b/lib/mediawiki_selenium/page_factory.rb
@@ -31,5 +31,8 @@
end
end
+ # @see #on_page
+ alias on on_page
+
end
end
diff --git a/lib/mediawiki_selenium/support/hooks.rb
b/lib/mediawiki_selenium/support/hooks.rb
index 3ced05c..76dc907 100644
--- a/lib/mediawiki_selenium/support/hooks.rb
+++ b/lib/mediawiki_selenium/support/hooks.rb
@@ -13,12 +13,6 @@
@scenario = scenario
end
-Before("@login") do
- ENV["MEDIAWIKI_PASSWORD"] = ENV[ENV["MEDIAWIKI_PASSWORD_VARIABLE"]] if
ENV["MEDIAWIKI_PASSWORD_VARIABLE"]
- puts "MEDIAWIKI_USER environment variable is not defined! Please export a
value for that variable before proceeding." unless ENV["MEDIAWIKI_USER"]
- puts "MEDIAWIKI_PASSWORD environment variable is not defined! Please export
a value for that variable before proceeding." unless ENV["MEDIAWIKI_PASSWORD"]
-end
-
AfterConfiguration do |config|
# Install a formatter that can be used to show feature-related warnings
pretty_format, io = config.formats.find { |(format, io)| format == "pretty" }
diff --git a/spec/environment_spec.rb b/spec/environment_spec.rb
index 253c6d3..7e98ad6 100644
--- a/spec/environment_spec.rb
+++ b/spec/environment_spec.rb
@@ -202,6 +202,53 @@
end
end
+ describe "#lookup" do
+ subject { env.lookup(key, id) }
+
+ let(:config) { { foo: "foo_value", foo_b: "foo_b_value", bar:
"bar_value" } }
+
+ context "given no alternative ID" do
+ let(:id) { nil }
+ let(:key) { :foo }
+
+ it "looks up the given key only" do
+ expect(subject).to eq("foo_value")
+ end
+
+ context "and a key that doesn't exist" do
+ let(:key) { :baz }
+
+ it { is_expected.to be(nil) }
+ end
+ end
+
+ context "given an alternative ID" do
+ let(:id) { :b }
+
+ context "for an alternative that exists" do
+ let(:key) { :foo }
+
+ it "returns the alternative value" do
+ expect(subject).to eq("foo_b_value")
+ end
+ end
+
+ context "for an alternative that doesn't exist" do
+ let(:key) { :bar }
+
+ it "falls back to the base value" do
+ expect(subject).to eq("bar_value")
+ end
+ end
+
+ context "and a key that doesn't exist" do
+ let(:key) { :baz }
+
+ it { is_expected.to be(nil) }
+ end
+ end
+ end
+
describe "#on_wiki" do
subject { env.on_wiki(:b) {} }
--
To view, visit https://gerrit.wikimedia.org/r/172007
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I58b105d36919c251b1ecf28ba21a539f61d03dbc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/selenium
Gerrit-Branch: env-abstraction-layer
Gerrit-Owner: Dduvall <[email protected]>
Gerrit-Reviewer: Cmcmahon <[email protected]>
Gerrit-Reviewer: Dduvall <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Zfilipin <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits