forked from mislav/will_paginate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
51 lines (42 loc) · 1.09 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'rspec'
require File.expand_path('../view_helpers/view_example_group', __FILE__)
begin
require 'ruby-debug'
rescue LoadError
# no debugger available
end
module MyExtras
protected
def include_phrase(string)
PhraseMatcher.new(string)
end
def collection(params = {})
if params[:total_pages]
params[:per_page] = 1
params[:total_entries] = params[:total_pages]
end
WillPaginate::Collection.new(params[:page] || 1, params[:per_page] || 30, params[:total_entries])
end
end
RSpec.configure do |config|
# config.include My::Pony, My::Horse, :type => :farm
config.include MyExtras
# config.predicate_matchers[:swim] = :can_swim?
config.mock_with :mocha
end
class PhraseMatcher
def initialize(string)
@string = string
@pattern = /\b#{string}\b/
end
def matches?(actual)
@actual = actual.to_s
@actual =~ @pattern
end
def failure_message
"expected #{@actual.inspect} to contain phrase #{@string.inspect}"
end
def negative_failure_message
"expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
end
end