|
ComplexExample
A more complicated example of what rcor can do.
IntroductionThis example shows how rcor can be used to seed staging data then demonstrate business rules as they apply to user functionality. Test: verify_rows.html<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<body>
<p>Given these users:</p>
<table>
<tr>
<th concordion:set="#username">Username</th>
<th concordion:execute="setupUser(#username, #TEXT)">Other</th>
</tr>
<tr>
<td>john.lennon</td>
<td>monkeys</td>
</tr>
<tr>
<td>ringo.starr</td>
<td>chucknorris</td>
</tr>
<tr>
<td>george.harrison</td>
<td>dishwasher</td>
</tr>
<tr>
<td>paul.mcartney</td>
<td>flamingweasel</td>
</tr>
</table>
<p>Searching for "<b concordion:set="#searchString">arr</b>" will return:</p>
<table concordion:verifyRows="#users = getSearchResultsFor(#searchString)">
<tr>
<th concordion:assertEquals="#user.name">Matching Usernames</th>
<th concordion:assertEquals="#user.other">and their Other field</th>
</tr>
<tr>
<td>george.harrison</td>
<td>dishwasher</td>
</tr>
<tr>
<td>ringo.starr</td>
<td>chucknorris</td>
</tr>
</table>
</body>
</html>Fixture: verify_rows_test.rb
class User
attr_accessor :name, :other
def initialize(name, other)
@name = name
@other = other
end
end
class VerifyRowsTest < ConcordionTestCase
def setup
@users = []
end
def setupUser(name, other)
#Here you would really call user_repository.save(user) or something similar.
@users << User.new(name,other)
end
def getSearchResultsFor(query)
#Likewise this would really run user_repository.search(query)
@users.select {|u| u.name.include?(query) }.sort{|x,y| x.name <=> y.name}
end
endDiscussionAs in all rcor tests, the fixture class calls the system under test. The difference here is the instrumentation of the table and th tags. Note that these rcor commands are not actually invoked on the th cells, but rather the corresponding td cells beneath them. The attributed output makes this clear: Output: verify_rows_test_output.html<html xmlns:concordion="http://www.concordion.org/2007/concordion"><head><link href="concordion.css" rel="stylesheet" type="text/css" /></head>
<body>
<p>Given these users:</p>
<table>
<tr>
<th concordion:set="#username">Username</th>
<th concordion:execute="setupUser(#username, #TEXT)">Other</th>
</tr>
<tr>
<td class="concordion_success" concordion:set="#username">john.lennon</td>
<td class="concordion_success" concordion:execute="setupUser(#username, #TEXT)">monkeys</td>
</tr>
<tr>
<td class="concordion_success" concordion:set="#username">ringo.starr</td>
<td class="concordion_success" concordion:execute="setupUser(#username, #TEXT)">chucknorris</td>
</tr>
<tr>
<td class="concordion_success" concordion:set="#username">george.harrison</td>
<td class="concordion_success" concordion:execute="setupUser(#username, #TEXT)">dishwasher</td>
</tr>
<tr>
<td class="concordion_success" concordion:set="#username">paul.mcartney</td>
<td class="concordion_success" concordion:execute="setupUser(#username, #TEXT)">flamingweasel</td>
</tr>
</table>
<p>Searching for "<b class="concordion_success" concordion:set="#searchString">arr</b>" will return:</p>
<table class="concordion_success" concordion:verifyrows="#users = getSearchResultsFor(#searchString)">
<tr>
<th concordion:assertequals="#user.name">Matching Usernames</th>
<th concordion:assertequals="#user.other">and their Other field</th>
</tr>
<tr>
<td concordion:assertequals="#user.name" class="concordion_success">george.harrison</td>
<td concordion:assertequals="#user.other" class="concordion_success">dishwasher</td>
</tr>
<tr>
<td concordion:assertequals="#user.name" class="concordion_success">ringo.starr</td>
<td concordion:assertequals="#user.other" class="concordion_success">chucknorris</td>
</tr>
</table>
</body>
</html>DifferencesReaders familiar with Concordion will note the instrumentation for tables differs from Concordion slightly, particularly the verifyRows command. See DifferencesBetweenRcorAndConcordion for more information about the ways Concordion and rcor differ. |
Sign in to add a comment