Sha256: 38167f3e4bbac84beccd5a504db68b1d1916cbd86c4c94c606ec0678c7256dd5

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers/output_to_fd'

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

25 entries across 25 versions & 1 rubygems

Version Path
mspec-1.5.17 spec/matchers/output_to_fd_spec.rb
mspec-1.5.16 spec/matchers/output_to_fd_spec.rb
mspec-1.5.15 spec/matchers/output_to_fd_spec.rb
mspec-1.5.14 spec/matchers/output_to_fd_spec.rb
mspec-1.5.13 spec/matchers/output_to_fd_spec.rb
mspec-1.0.0 spec/matchers/output_to_fd_spec.rb
mspec-1.3.1 spec/matchers/output_to_fd_spec.rb
mspec-1.5.0 spec/matchers/output_to_fd_spec.rb
mspec-1.5.1 spec/matchers/output_to_fd_spec.rb
mspec-1.5.11 spec/matchers/output_to_fd_spec.rb
mspec-1.5.12 spec/matchers/output_to_fd_spec.rb
mspec-1.5.2 spec/matchers/output_to_fd_spec.rb
mspec-1.5.3 spec/matchers/output_to_fd_spec.rb
mspec-1.5.4 spec/matchers/output_to_fd_spec.rb
mspec-1.3.0 spec/matchers/output_to_fd_spec.rb
mspec-1.1.0 spec/matchers/output_to_fd_spec.rb
mspec-1.5.10 spec/matchers/output_to_fd_spec.rb
mspec-1.4.0 spec/matchers/output_to_fd_spec.rb
mspec-1.1.1 spec/matchers/output_to_fd_spec.rb
mspec-1.2.0 spec/matchers/output_to_fd_spec.rb