Sha256: 8c2e737649759b372a71440d68aca7eaf5f5264c50b6352c4131ee013a2a9580

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'

describe OutputToFDMatcher do
  # Figure out how in the hell to achieve this
  it "matches when running the block produces the expected output to the given FD" do
    output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
  end

  it "does not match if running the block does not produce the expected output to the FD" do
    output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
  end

  it "defaults to matching against STDOUT" do
    output_to_fd("Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
  end

  it "accepts any IO instance" do
    io = IO.new STDOUT.fileno
    output_to_fd("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
  end

  it "allows matching with a Regexp" do
    s = "Hi there\n"
    output_to_fd(/Hi/, STDERR).matches?(lambda { $stderr.print s }).should == true
    output_to_fd(/Hi?/, STDERR).matches?(lambda { $stderr.print s }).should == true
    output_to_fd(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s }).should == true
    output_to_fd(/.*/, STDERR).matches?(lambda { $stderr.print s }).should == true
    output_to_fd(/H.*?here/, STDERR).matches?(lambda { $stderr.print s }).should == true
    output_to_fd(/Ahoy/, STDERR).matches?(lambda { $stderr.print s }).should == false
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mspec-1.9.1 spec/matchers/output_to_fd_spec.rb
mspec-1.9.0 spec/matchers/output_to_fd_spec.rb
mspec-1.8.0 spec/matchers/output_to_fd_spec.rb
mspec-1.7.0 spec/matchers/output_to_fd_spec.rb
mspec-1.6.0 spec/matchers/output_to_fd_spec.rb
mspec-1.5.21 spec/matchers/output_to_fd_spec.rb
mspec-1.5.20 spec/matchers/output_to_fd_spec.rb
mspec-1.5.19 spec/matchers/output_to_fd_spec.rb
mspec-1.5.18 spec/matchers/output_to_fd_spec.rb