spec/spec_helper.rb in hostsfile-0.0.1 vs spec/spec_helper.rb in hostsfile-0.0.2

- old
+ new

@@ -1,4 +1,38 @@ require 'bundler/setup' Bundler.setup +require 'simplecov' +require 'simplecov-console' +require 'coveralls' +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + Coveralls::SimpleCov::Formatter +] + +SimpleCov.start do + add_filter "/spec/" +end + + +def fixture_path + File.expand_path("../fixtures", __FILE__) +end + +def fixture(*segments) + fakefs_status = (defined? FakeFS).nil? ? false : FakeFS.activated? + FakeFS.deactivate! if fakefs_status + fixture = File.read(File.join(fixture_path, *segments)) + FakeFS.activate! if fakefs_status + fixture +end + +def fixture_to_fakefs(name, filepath) + raise "FakeFS required but not installed or activated" unless !(defined? FakeFS).nil? && FakeFS.activated? + + fixture_content = fixture(name) + FileUtils.mkdir_p(File.dirname(filepath)) + File.open(filepath, "w") { |f| f.write(fixture_content) } +end + require 'hostsfile' \ No newline at end of file