rspec_sequel_matchers 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,24 +15,24 @@ describe "validate_length_range_matcher" do
15
15
 
16
16
  describe "arguments" do
17
17
  it "should require attribute" do
18
- lambda{
18
+ expect do
19
19
  @matcher = validate_length_range
20
- }.should raise_error
20
+ end.to raise_error
21
21
  end
22
22
  it "should require additionnal parameters" do
23
- lambda{
23
+ expect do
24
24
  @matcher = validate_length_range :name
25
- }.should raise_error
25
+ end.to raise_error
26
26
  end
27
27
  it "should refuse invalid additionnal parameters" do
28
- lambda{
28
+ expect do
29
29
  @matcher = validate_length_range :id, :name
30
- }.should raise_error
30
+ end.to raise_error
31
31
  end
32
32
  it "should accept valid additionnal parameters" do
33
- lambda{
33
+ expect do
34
34
  @matcher = validate_length_range 1..10, :name
35
- }.should_not raise_error
35
+ end.not_to raise_error
36
36
  end
37
37
  end
38
38
 
@@ -40,49 +40,49 @@ describe "validate_length_range_matcher" do
40
40
  describe "without option" do
41
41
  it "should contain a description" do
42
42
  @matcher = validate_length_range 1..10, :name
43
- @matcher.description.should == "validate length of :name is included in 1..10"
43
+ expect( @matcher.description ).to eq "validate length of :name is included in 1..10"
44
44
  end
45
45
  it "should set failure messages" do
46
46
  @matcher = validate_length_range 1..10, :name
47
47
  @matcher.matches? subject
48
- @matcher.failure_message.should == "expected Item to " + @matcher.description
49
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
48
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
49
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
50
50
  end
51
51
  end
52
52
  describe "with options" do
53
53
  it "should contain a description" do
54
54
  @matcher = validate_length_range 1..10, :name, :allow_nil => true
55
- @matcher.description.should == "validate length of :name is included in 1..10 with option(s) :allow_nil => true"
55
+ expect( @matcher.description ).to eq "validate length of :name is included in 1..10 with option(s) :allow_nil => true"
56
56
  end
57
57
  it "should set failure messages" do
58
58
  @matcher = validate_length_range 1..10, :price, :allow_nil => true
59
59
  @matcher.matches? subject
60
- @matcher.failure_message.should == "expected Item to " + @matcher.description
61
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
60
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
61
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
62
62
  end
63
63
  it "should explicit used options if different than expected" do
64
64
  @matcher = validate_length_range 1..10, :name, :allow_blank => true
65
65
  @matcher.matches? subject
66
66
  explanation = " but called with option(s) :allow_nil => true instead"
67
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
68
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
67
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
68
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
69
69
  end
70
70
  it "should warn if invalid options are used" do
71
71
  @matcher = validate_length_range 1..10, :name, :allow_anything => true
72
72
  @matcher.matches? subject
73
73
  explanation = " but option :allow_anything is not valid"
74
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
75
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
74
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
75
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
80
  describe "matchers" do
81
- it{ should validate_length_range(1..10, :name) }
82
- it{ should validate_length_range(1..10, :name, :allow_nil => true) }
83
- it{ should_not validate_length_range(1..10, :price) }
84
- it{ should_not validate_length_range(0..10, :name) }
85
- it{ should_not validate_length_range(1..10, :name, :allow_blank => true) }
81
+ it{ is_expected.to validate_length_range(1..10, :name) }
82
+ it{ is_expected.to validate_length_range(1..10, :name, :allow_nil => true) }
83
+ it{ is_expected.not_to validate_length_range(1..10, :price) }
84
+ it{ is_expected.not_to validate_length_range(0..10, :name) }
85
+ it{ is_expected.not_to validate_length_range(1..10, :name, :allow_blank => true) }
86
86
  end
87
87
 
88
88
  end
@@ -15,24 +15,24 @@ describe "validate_max_length_matcher" do
15
15
 
16
16
  describe "arguments" do
17
17
  it "should require attribute" do
18
- lambda{
18
+ expect do
19
19
  @matcher = validate_max_length
20
- }.should raise_error
20
+ end.to raise_error
21
21
  end
22
22
  it "should require additionnal parameters" do
23
- lambda{
23
+ expect do
24
24
  @matcher = validate_max_length :name
25
- }.should raise_error
25
+ end.to raise_error
26
26
  end
27
27
  it "should refuse invalid additionnal parameters" do
28
- lambda{
28
+ expect do
29
29
  @matcher = validate_max_length :id, :name
30
- }.should raise_error
30
+ end.to raise_error
31
31
  end
32
32
  it "should accept valid additionnal parameters" do
33
- lambda{
33
+ expect do
34
34
  @matcher = validate_max_length 4, :name
35
- }.should_not raise_error
35
+ end.not_to raise_error
36
36
  end
37
37
  end
38
38
 
@@ -40,49 +40,49 @@ describe "validate_max_length_matcher" do
40
40
  describe "without option" do
41
41
  it "should contain a description" do
42
42
  @matcher = validate_max_length 4, :name
43
- @matcher.description.should == "validate length of :name is less than or equal to 4"
43
+ expect( @matcher.description ).to eq "validate length of :name is less than or equal to 4"
44
44
  end
45
45
  it "should set failure messages" do
46
46
  @matcher = validate_max_length 4, :name
47
47
  @matcher.matches? subject
48
- @matcher.failure_message.should == "expected Item to " + @matcher.description
49
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
48
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
49
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
50
50
  end
51
51
  end
52
52
  describe "with options" do
53
53
  it "should contain a description" do
54
54
  @matcher = validate_max_length 4, :name, :allow_nil => true
55
- @matcher.description.should == "validate length of :name is less than or equal to 4 with option(s) :allow_nil => true"
55
+ expect( @matcher.description ).to eq "validate length of :name is less than or equal to 4 with option(s) :allow_nil => true"
56
56
  end
57
57
  it "should set failure messages" do
58
58
  @matcher = validate_max_length 4, :price, :allow_nil => true
59
59
  @matcher.matches? subject
60
- @matcher.failure_message.should == "expected Item to " + @matcher.description
61
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
60
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
61
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
62
62
  end
63
63
  it "should explicit used options if different than expected" do
64
64
  @matcher = validate_max_length 4, :name, :allow_blank => true
65
65
  @matcher.matches? subject
66
66
  explanation = " but called with option(s) :allow_nil => true instead"
67
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
68
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
67
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
68
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
69
69
  end
70
70
  it "should warn if invalid options are used" do
71
71
  @matcher = validate_max_length 4, :name, :allow_anything => true
72
72
  @matcher.matches? subject
73
73
  explanation = " but option :allow_anything is not valid"
74
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
75
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
74
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
75
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
80
  describe "matchers" do
81
- it{ should validate_max_length(4, :name) }
82
- it{ should validate_max_length(4, :name, :allow_nil => true) }
83
- it{ should_not validate_max_length(4, :price) }
84
- it{ should_not validate_max_length(3, :name) }
85
- it{ should_not validate_max_length(4, :name, :allow_blank => true) }
81
+ it{ is_expected.to validate_max_length(4, :name) }
82
+ it{ is_expected.to validate_max_length(4, :name, :allow_nil => true) }
83
+ it{ is_expected.not_to validate_max_length(4, :price) }
84
+ it{ is_expected.not_to validate_max_length(3, :name) }
85
+ it{ is_expected.not_to validate_max_length(4, :name, :allow_blank => true) }
86
86
  end
87
87
 
88
88
  end
@@ -15,24 +15,24 @@ describe "validate_min_length_matcher" do
15
15
 
16
16
  describe "arguments" do
17
17
  it "should require attribute" do
18
- lambda{
18
+ expect do
19
19
  @matcher = validate_min_length
20
- }.should raise_error
20
+ end.to raise_error
21
21
  end
22
22
  it "should require additionnal parameters" do
23
- lambda{
23
+ expect do
24
24
  @matcher = validate_min_length :name
25
- }.should raise_error
25
+ end.to raise_error
26
26
  end
27
27
  it "should refuse invalid additionnal parameters" do
28
- lambda{
28
+ expect do
29
29
  @matcher = validate_min_length :id, :name
30
- }.should raise_error
30
+ end.to raise_error
31
31
  end
32
32
  it "should accept valid additionnal parameters" do
33
- lambda{
33
+ expect do
34
34
  @matcher = validate_min_length 4, :name
35
- }.should_not raise_error
35
+ end.not_to raise_error
36
36
  end
37
37
  end
38
38
 
@@ -40,49 +40,49 @@ describe "validate_min_length_matcher" do
40
40
  describe "without option" do
41
41
  it "should contain a description" do
42
42
  @matcher = validate_min_length 4, :name
43
- @matcher.description.should == "validate length of :name is greater than or equal to 4"
43
+ expect( @matcher.description ).to eq "validate length of :name is greater than or equal to 4"
44
44
  end
45
45
  it "should set failure messages" do
46
46
  @matcher = validate_min_length 4, :name
47
47
  @matcher.matches? subject
48
- @matcher.failure_message.should == "expected Item to " + @matcher.description
49
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
48
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
49
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
50
50
  end
51
51
  end
52
52
  describe "with options" do
53
53
  it "should contain a description" do
54
54
  @matcher = validate_min_length 4, :name, :allow_nil => true
55
- @matcher.description.should == "validate length of :name is greater than or equal to 4 with option(s) :allow_nil => true"
55
+ expect( @matcher.description ).to eq "validate length of :name is greater than or equal to 4 with option(s) :allow_nil => true"
56
56
  end
57
57
  it "should set failure messages" do
58
58
  @matcher = validate_min_length 4, :price, :allow_nil => true
59
59
  @matcher.matches? subject
60
- @matcher.failure_message.should == "expected Item to " + @matcher.description
61
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
60
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
61
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
62
62
  end
63
63
  it "should explicit used options if different than expected" do
64
64
  @matcher = validate_min_length 4, :name, :allow_blank => true
65
65
  @matcher.matches? subject
66
66
  explanation = " but called with option(s) :allow_nil => true instead"
67
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
68
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
67
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
68
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
69
69
  end
70
70
  it "should warn if invalid options are used" do
71
71
  @matcher = validate_min_length 4, :name, :allow_anything => true
72
72
  @matcher.matches? subject
73
73
  explanation = " but option :allow_anything is not valid"
74
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
75
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
74
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
75
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
76
76
  end
77
77
  end
78
78
  end
79
79
 
80
80
  describe "matchers" do
81
- it{ should validate_min_length(4, :name) }
82
- it{ should validate_min_length(4, :name, :allow_nil => true) }
83
- it{ should_not validate_min_length(4, :price) }
84
- it{ should_not validate_min_length(3, :name) }
85
- it{ should_not validate_min_length(4, :name, :allow_blank => true) }
81
+ it{ is_expected.to validate_min_length(4, :name) }
82
+ it{ is_expected.to validate_min_length(4, :name, :allow_nil => true) }
83
+ it{ is_expected.not_to validate_min_length(4, :price) }
84
+ it{ is_expected.not_to validate_min_length(3, :name) }
85
+ it{ is_expected.not_to validate_min_length(4, :name, :allow_blank => true) }
86
86
  end
87
87
 
88
88
  end
@@ -15,14 +15,14 @@ describe "validate_not_string_matcher" do
15
15
 
16
16
  describe "arguments" do
17
17
  it "should require attribute" do
18
- lambda{
18
+ expect do
19
19
  @matcher = validate_not_string
20
- }.should raise_error
20
+ end.to raise_error
21
21
  end
22
22
  it "should refuse additionnal parameters" do
23
- lambda{
23
+ expect do
24
24
  @matcher = validate_not_string :name, :id
25
- }.should raise_error
25
+ end.to raise_error
26
26
  end
27
27
  end
28
28
 
@@ -30,48 +30,48 @@ describe "validate_not_string_matcher" do
30
30
  describe "without option" do
31
31
  it "should contain a description" do
32
32
  @matcher = validate_not_string :name
33
- @matcher.description.should == "validate that :name is not a string"
33
+ expect( @matcher.description ).to eq "validate that :name is not a string"
34
34
  end
35
35
  it "should set failure messages" do
36
36
  @matcher = validate_not_string :name
37
37
  @matcher.matches? subject
38
- @matcher.failure_message.should == "expected Item to " + @matcher.description
39
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
38
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
39
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
40
40
  end
41
41
  end
42
42
  describe "with options" do
43
43
  it "should contain a description" do
44
44
  @matcher = validate_not_string :name, :allow_nil => true
45
- @matcher.description.should == "validate that :name is not a string with option(s) :allow_nil => true"
45
+ expect( @matcher.description ).to eq "validate that :name is not a string with option(s) :allow_nil => true"
46
46
  end
47
47
  it "should set failure messages" do
48
48
  @matcher = validate_not_string :price, :allow_nil => true
49
49
  @matcher.matches? subject
50
- @matcher.failure_message.should == "expected Item to " + @matcher.description
51
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
50
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
51
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
52
52
  end
53
53
  it "should explicit used options if different than expected" do
54
54
  @matcher = validate_not_string :name, :allow_blank => true
55
55
  @matcher.matches? subject
56
56
  explanation = " but called with option(s) :allow_nil => true instead"
57
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
58
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
57
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
58
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
59
59
  end
60
60
  it "should warn if invalid options are used" do
61
61
  @matcher = validate_not_string :name, :allow_anything => true
62
62
  @matcher.matches? subject
63
63
  explanation = " but option :allow_anything is not valid"
64
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
65
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
64
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
65
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
66
66
  end
67
67
  end
68
68
  end
69
69
 
70
70
  describe "matchers" do
71
- it{ should validate_not_string(:name) }
72
- it{ should validate_not_string(:name, :allow_nil => true) }
73
- it{ should_not validate_not_string(:price) }
74
- it{ should_not validate_not_string(:name, :allow_blank => true) }
71
+ it{ is_expected.to validate_not_string(:name) }
72
+ it{ is_expected.to validate_not_string(:name, :allow_nil => true) }
73
+ it{ is_expected.not_to validate_not_string(:price) }
74
+ it{ is_expected.not_to validate_not_string(:name, :allow_blank => true) }
75
75
  end
76
76
 
77
77
  end
@@ -15,14 +15,14 @@ describe "validate_numeric_matcher" do
15
15
 
16
16
  describe "arguments" do
17
17
  it "should require attribute" do
18
- lambda{
18
+ expect do
19
19
  @matcher = validate_numeric
20
- }.should raise_error
20
+ end.to raise_error
21
21
  end
22
22
  it "should refuse additionnal parameters" do
23
- lambda{
23
+ expect do
24
24
  @matcher = validate_numeric :name, :id
25
- }.should raise_error
25
+ end.to raise_error
26
26
  end
27
27
  end
28
28
 
@@ -30,48 +30,48 @@ describe "validate_numeric_matcher" do
30
30
  describe "without option" do
31
31
  it "should contain a description" do
32
32
  @matcher = validate_numeric :name
33
- @matcher.description.should == "validate that :name is a valid float"
33
+ expect( @matcher.description ).to eq "validate that :name is a valid float"
34
34
  end
35
35
  it "should set failure messages" do
36
36
  @matcher = validate_numeric :name
37
37
  @matcher.matches? subject
38
- @matcher.failure_message.should == "expected Item to " + @matcher.description
39
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
38
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
39
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
40
40
  end
41
41
  end
42
42
  describe "with options" do
43
43
  it "should contain a description" do
44
44
  @matcher = validate_numeric :name, :allow_nil => true
45
- @matcher.description.should == "validate that :name is a valid float with option(s) :allow_nil => true"
45
+ expect( @matcher.description ).to eq "validate that :name is a valid float with option(s) :allow_nil => true"
46
46
  end
47
47
  it "should set failure messages" do
48
48
  @matcher = validate_numeric :price, :allow_nil => true
49
49
  @matcher.matches? subject
50
- @matcher.failure_message.should == "expected Item to " + @matcher.description
51
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description
50
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description
51
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description
52
52
  end
53
53
  it "should explicit used options if different than expected" do
54
54
  @matcher = validate_numeric :name, :allow_blank => true
55
55
  @matcher.matches? subject
56
56
  explanation = " but called with option(s) :allow_nil => true instead"
57
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
58
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
57
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
58
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
59
59
  end
60
60
  it "should warn if invalid options are used" do
61
61
  @matcher = validate_numeric :name, :allow_anything => true
62
62
  @matcher.matches? subject
63
63
  explanation = " but option :allow_anything is not valid"
64
- @matcher.failure_message.should == "expected Item to " + @matcher.description + explanation
65
- @matcher.negative_failure_message.should == "expected Item to not " + @matcher.description + explanation
64
+ expect( @matcher.failure_message ).to eq "expected Item to " + @matcher.description + explanation
65
+ expect( @matcher.failure_message_when_negated ).to eq "expected Item to not " + @matcher.description + explanation
66
66
  end
67
67
  end
68
68
  end
69
69
 
70
70
  describe "matchers" do
71
- it{ should validate_numeric(:name) }
72
- it{ should validate_numeric(:name, :allow_nil => true) }
73
- it{ should_not validate_numeric(:price) }
74
- it{ should_not validate_numeric(:name, :allow_blank => true) }
71
+ it{ is_expected.to validate_numeric(:name) }
72
+ it{ is_expected.to validate_numeric(:name, :allow_nil => true) }
73
+ it{ is_expected.not_to validate_numeric(:price) }
74
+ it{ is_expected.not_to validate_numeric(:name, :allow_blank => true) }
75
75
  end
76
76
 
77
77
  end