I want to use RSpec mocks to provide canned block input.
Ruby:
class Parser attr_accessor :extracted def parse(fname) File.open(fname).each do |line| extracted = line if line =~ /^RCS file: (.*),v$/ end end end
RSpec:
describe Parser before do @parser = Parser.new @lines = mock("lines") @lines.stub!(:each) File.stub!(:open).and_return(@lines) end it "should extract a filename into extracted" do linetext = [ "RCS file: hello,v\n", "bla bla bla\n" ]
This is a way to verify the correct operation of indoor units by transferring embedded data into it. But I can’t understand how to make the actual power using the mechanical mechanism of RSpec.
update: looks like the problem is not with linetext, but with:
@parser.should_receive('extracted=')
this is not what he called, replacing it in ruby code with self.extracted = helps a bit, but it feels somehow wrong.
ruby mocking rspec rspec-mocks
Evgeny
source share