github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ignu / specish

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 5
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: 95905fc

click here to add a description

click here to add a homepage

  • Branches (2)
    • AutoMocking
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Examples of writing specs in C# with NUnit. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added ruby parser for specs 
U-nice\ignu (author)
Sat Feb 21 17:19:03 -0800 2009
commit  95905fc980d208e6391c08e2a176bc83b4ceea3c
tree    dc9af2a498560a0ba370fff2bc23860cd5ad3196
parent  ec42a1d67164ed1d9fa1e22f4a672acb1d2884d7
specish / Specish / nunit_spec_extensions.cs Specish/nunit_spec_extensions.cs
100644 193 lines (159 sloc) 5.982 kb
edit raw blame history
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Collections;
using System.Text.RegularExpressions;
using NUnit.Framework;
 
namespace Specish
{
    public delegate void MethodThatThrows();
 
    /// <summary>
    /// Extention methods that make unit test asserts more fluid and readable.
    ///
    /// Modified from CodeIncubator: http://code.google.com/p/codeincubator/
    /// </summary>
    public static class NUnitSpecExtensions
    {
        public static void ShouldBeFalse(this bool condition)
        {
            Assert.IsFalse(condition);
        }
 
        public static void ShouldBeTrue(this bool condition)
        {
            Assert.IsTrue(condition);
        }
 
        public static object ShouldEqual(this object actual, object expected)
        {
            Assert.AreEqual(expected, actual);
            return expected;
        }
 
        public static object ShouldNotEqual(this object actual, object expected)
        {
            Assert.AreNotEqual(expected, actual);
            return expected;
        }
 
        public static void ShouldBeNull(this object anObject)
        {
            Assert.IsNull(anObject);
        }
 
        public static void ShouldNotBeNull(this object anObject)
        {
            Assert.IsNotNull(anObject);
        }
 
        public static void ShouldNotBeNullOrEmpty(this string aString)
        {
            Assert.That(!String.IsNullOrEmpty(aString), "String should not be null or empty");
        }
 
        public static object ShouldBeTheSameAs(this object actual, object expected)
        {
            Assert.AreSame(expected, actual);
            return expected;
        }
 
        public static object ShouldNotBeTheSameAs(this object actual, object expected)
        {
            Assert.AreNotSame(expected, actual);
            return expected;
        }
 
        public static void ShouldBeOfType(this object actual, Type expected)
        {
            Assert.IsInstanceOfType(expected, actual);
        }
 
        public static void ShouldNotBeOfType(this object actual, Type expected)
        {
            Assert.IsNotInstanceOfType(expected, actual);
        }
 
        public static void ShouldContain(this IList actual, object expected)
        {
            Assert.Contains(expected, actual);
        }
 
        public static IComparable ShouldBeGreaterThanOrEqualTo(this IComparable arg1, IComparable arg2)
        {
            Assert.GreaterOrEqual(arg1, arg2);
            return arg2;
        }
 
        public static IComparable ShouldBeGreaterThan(this IComparable arg1, IComparable arg2)
        {
            Assert.Greater(arg1, arg2);
            return arg2;
        }
 
        public static IComparable ShouldBeLessThan(this IComparable arg1, IComparable arg2)
        {
            Assert.Less(arg1, arg2);
            return arg2;
        }
 
        public static void ShouldBeEmpty(this ICollection collection)
        {
            Assert.IsEmpty(collection);
        }
 
        public static void ShouldBeEmpty(this string aString)
        {
            Assert.IsEmpty(aString);
        }
 
        public static void ShouldNotBeEmpty(this ICollection collection)
        {
            Assert.IsNotEmpty(collection);
        }
 
        public static void ShouldNotBeEmpty(this string aString)
        {
            Assert.IsNotEmpty(aString);
        }
 
        public static void ShouldContain(this string actual, string expected)
        {
            StringAssert.Contains(expected, actual);
        }
 
        public static void ShouldNotContain(this string actual, string expected)
        {
            Assert.That(actual.IndexOf(expected) < 0);
        }
 
        public static string ShouldBeEqualIgnoringCase(this string actual, string expected)
        {
            StringAssert.AreEqualIgnoringCase(expected, actual);
            return expected;
        }
 
        public static void ShouldEndWith(this string actual, string expected)
        {
            StringAssert.EndsWith(expected, actual);
        }
 
        public static void ShouldStartWith(this string actual, string expected)
        {
            StringAssert.StartsWith(expected, actual);
        }
 
        public static void ShouldContainErrorMessage(this Exception exception, string expected)
        {
            StringAssert.Contains(expected, exception.Message);
        }
 
        public static Exception ShouldBeThrownBy(this Type exceptionType, MethodThatThrows method)
        {
            Exception exception = null;
 
            try
            {
                method();
            }
            catch (Exception e)
            {
                Assert.AreEqual(exceptionType, e.GetType());
                exception = e;
            }
 
            if (exception == null)
            {
                Assert.Fail(String.Format("Expected {0} to be thrown.", exceptionType.FullName));
            }
 
            return exception;
        }
 
        public static void ShouldEqualSqlDate(this DateTime actual, DateTime expected)
        {
            TimeSpan timeSpan = actual - expected;
            Assert.Less(Math.Abs(timeSpan.TotalMilliseconds), 3);
        }
 
        public static void ShouldMatch(this string actual, string pattern)
        {
            Regex regex = new Regex(pattern);
            Assert.That(regex.Matches(actual).Count > 0, "Regular Expression (" + pattern + ") does not match: \r\n" + actual);
        }
 
        public static void ShouldContainExactly(this string actual, int count, string pattern)
        {
            Regex regex = new Regex(pattern);
            Assert.That(regex.Matches(actual).Count == count,
                string.Format("Regular Expression ({0}) does not contain {1} matches in : {2}",
                    pattern, count, actual));
        }
    }
 
}
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server