spec/spec_helper.rb in rconf-0.7.8 vs spec/spec_helper.rb in rconf-0.7.9
- old
+ new
@@ -17,9 +17,29 @@
RSpec.configure do |c|
c.mock_with(:flexmock)
end
+# Create configurator for testing and setup common mocks
+#
+# === Parameters
+# code(String):: Code using rconf language syntax used to initialize configurator
+# opts[:enable_updater](TrueClass|FalseClass):: Don't mock out environment updater if set
+#
+# === Return
+# configurator(RightConf::Configurator):: Created configurator
+def create_configurator(code, opts={})
+ lang = RightConf::Language.parse(code)
+ configurator = lang.configurators.first
+ [:report_check, :report_error, :report_result, :report_success].each do |meth|
+ flexmock(configurator).should_receive(meth)
+ end
+ flexmock(configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
+ flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.rconf')).and_return(false)
+ flexmock(RightConf::EnvironmentUpdater).should_receive(:update) unless opts[:enable_updater]
+ configurator
+end
+
# Helper method to mock Command.execute
#
# === Parameters
# Parameters are passed through to flexmock 'with' method
#