From fd3b8ef7f28197254f16bce59f9daa936d76d0a8 Mon Sep 17 00:00:00 2001 From: Wes Oldenbeuving Date: Tue, 15 Sep 2009 16:08:47 +0200 Subject: [PATCH] Added spec for Cli#add Also fixed a bug in fakefs' File#open and use FakeFS.(de)activate! in before/after blocks to add rcov support. --- spec/blocklist/cli_spec.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/spec/blocklist/cli_spec.rb b/spec/blocklist/cli_spec.rb index 151f417..d826192 100644 --- a/spec/blocklist/cli_spec.rb +++ b/spec/blocklist/cli_spec.rb @@ -1,8 +1,16 @@ require File.join(File.dirname(__FILE__), %w[.. spec_helper]) require 'blocklist/cli' -require 'fakefs' +require 'fakefs/safe' describe Blocklist::Cli do + before(:each) do + FakeFS.activate! + end + + after(:each) do + FakeFS.deactivate! + end + def fake_hosts(content='') File.open('/etc/hosts','w') {|f| f.puts content} end @@ -22,8 +30,22 @@ def fake_hosts(content='') # blocked STR cli = Blocklist::Cli.new(%w[list]) - cli.should_receive(:puts).with("\nlocalhost\nblocked") + cli.should_receive(:puts).with("localhost\nblocked") + cli.run + end + end + + describe 'add' do + it "should add a domain and its www-subdomain to a block's lines" do + fake_hosts <<-STR +# localhost + STR + cli = Blocklist::Cli.new(%w[add localhost example.org]) cli.run + File.read('/etc/hosts').should == <<-STR +# localhost +127.0.0.1 example.org www.example.org + STR end end end