Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Added spec for Cli#add
Browse files Browse the repository at this point in the history
Also fixed a bug in fakefs' File#open and use FakeFS.(de)activate! in before/after blocks to add rcov support.
  • Loading branch information
Narnach committed Sep 15, 2009
1 parent bd41822 commit fd3b8ef
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions 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
Expand All @@ -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

0 comments on commit fd3b8ef

Please sign in to comment.