Changeset 566

Show
Ignore:
Timestamp:
06/24/08 16:16:36 (2 months ago)
Author:
bbleything
Message:
  • classes[ :argument ].coverage.should be( 100% ) => pass
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • linen/trunk/spec/spec_helper.rb

    r399 r566  
    3333##################################################################################### 
    3434 
     35### ArgumentMatchers 
     36### 
     37### These matchers are used to test argument handling. 
     38### 
     39###  * ValidationMatcher -- lets us check for acceptance and rejection of input values 
     40module ArgumentMatchers 
     41    class ValidationMatcher 
     42        def initialize( input, mode = :accept ) 
     43            @input = input 
     44            @mode  = mode 
     45        end 
     46         
     47        def matches?( argument ) 
     48            @argument = argument 
     49             
     50            begin 
     51                argument.process( @input ) 
     52            rescue Linen::Plugin::ArgumentError 
     53                result = :rejected 
     54                # the exception means the argument was rejected, so return true 
     55                # in reject mode and false in accept mode. 
     56                return true if @mode == :reject 
     57                return false 
     58            else 
     59                # no exception means the argument was accepted 
     60                return false if @mode == :reject 
     61                return true 
     62            end 
     63        end 
     64         
     65        def failure_message 
     66            "expected argument #{@argument} to accept '#{@input}', but it was rejected." 
     67        end 
     68         
     69        def negative_failure_message 
     70            "expected argument #{@argument} to reject '#{@input}', but it was accepted." 
     71        end 
     72    end 
     73     
     74    def accept( input ) 
     75        ArgumentMatchers::ValidationMatcher.new( input, :accept ) 
     76    end 
     77     
     78    def reject( input ) 
     79        ArgumentMatchers::ValidationMatcher.new( input, :reject ) 
     80    end 
     81end 
    3582 
    3683### CompletionMatchers 
     
    3885### These matchers are used to test the tab-completion facilities of the CLI handler 
    3986### 
    40 ###  * AmbiguityMatcher -- lets us do completing( 'foo' ).should be_ambiguous 
     87###  * AmbiguityMatcher         -- lets us do completing( 'foo' ).should be_ambiguous 
    4188###  * SuggestCandidatesMatcher -- lets us do completing( 'foo' ).should suggest_candidates( ary ) 
    42 ###  * ExpandToMatcher -- lets us do completing( 'foo' ).should expand_to( result ) 
     89###  * ExpandToMatcher          -- lets us do completing( 'foo' ).should expand_to( result ) 
    4390module CompletionMatchers 
    4491    # helper method to save some typing.  We don't care that this returns 
     
    133180    end 
    134181end 
     182