Skip to content

Commit

Permalink
Replace rspec mocking with rr
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro committed Apr 24, 2010
1 parent 6e5e564 commit 53dcc53
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -13,6 +13,7 @@ begin
gem.add_dependency "dnssd", "1.3.1"
gem.add_dependency "rspec"
gem.add_development_dependency "rspec", "1.3.0"
gem.add_development_dependency "rr", "0.10.11"
gem.add_development_dependency "yard", "0.5.3"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Expand Down
4 changes: 2 additions & 2 deletions lib/specjour/rsync_daemon.rb
Expand Up @@ -30,8 +30,8 @@ def pid_file

def start
write_config
system *command
at_exit { stop }
Kernel.system *command
Kernel.at_exit { stop }
end

def stop
Expand Down
2 changes: 1 addition & 1 deletion spec/cpu_spec.rb
Expand Up @@ -18,7 +18,7 @@
end

before do
Specjour::CPU.stub(:command => hostinfo)
stub(Specjour::CPU).command.returns(hostinfo)
end

it "returns the number of logically available processors" do
Expand Down
34 changes: 15 additions & 19 deletions spec/rsync_daemon_spec.rb
Expand Up @@ -6,58 +6,54 @@
end

before do
stub(:system)
stub(:at_exit)
subject.stub(:write_config)
stub(Kernel).system
stub(Kernel).at_exit
stub(subject).write_config
end

describe "#config_directory" do
specify { subject.config_directory.should == '/tmp/seasonal/.specjour' }
end

describe "#config_file" do
specify { subject.config_file.should == '/tmp/seasonal/.specjour/rsyncd.conf' }
end
specify { subject.config_directory.should == '/tmp/seasonal/.specjour' }
specify { subject.config_file.should == '/tmp/seasonal/.specjour/rsyncd.conf' }

describe "#start" do
it "writes the config" do
subject.should_receive(:write_config)
mock(subject).write_config
subject.start
end

it "executes the system command" do
subject.should_receive(:system).with(*subject.send(:command))
mock(Kernel).system(*subject.send(:command))
subject.start
end

it "stops at_exit" do
subject.should_receive(:at_exit)
mock(subject).stop
mock.proxy(Kernel).at_exit.yields(subject)
subject.start
end
end

describe "#stop" do
context "with pid" do
before do
subject.stub(:pid => 100_000_000)
Process.stub(:kill)
FileUtils.stub(:rm)
stub(subject).pid.returns(100_000_000)
stub(Process).kill
stub(FileUtils).rm
end

it "kills the pid with TERM" do
Process.should_receive(:kill).with('TERM', subject.pid)
mock(Process).kill('TERM', subject.pid)
subject.stop
end

it "removes the pid file" do
FileUtils.should_receive(:rm).with(subject.pid_file)
mock(FileUtils).rm(subject.pid_file)
subject.stop
end
end

context "without pid" do
it "does nothing" do
subject.stub(:pid => nil)
stub(subject).pid
subject.stop.should be_nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -4,5 +4,5 @@
require 'spec/autorun'

Spec::Runner.configure do |config|

config.mock_with :rr
end

0 comments on commit 53dcc53

Please sign in to comment.