Running FitNesse tests stored in variable - fitnesse

I'm trying to get FitNesse (slim tests running via fitSharp) to process tables stored in a variable. Both approach A & B below render the same on the page, but only approach B will run.
Approach A
!define test (
| Table:myTest | someValue |
)
${test}
Approach B
| Table:myTest | someValue |
This example is rather superficial, but in my tests I'm looking to vary some parameters and reexecute the same test (without a lot of copy and paste).
Adding additional details requested;
Approach A renders this to page when saving;
<br><span class="meta">variable defined: test=
| Table:myTest | someValue |
</span>
<br><br><table>
<tbody><tr class="slimRowTitle">
<td>Table:myTest</td>
<td>someValue</td>
</tr>
</tbody></table>
<br>
...but when running the test the page doesn't seem to process the table and shows just the variable definition
<br><span class="meta">variable defined: test=
| Table:myTest | someValue |
</span>
<br><br><br></div>

Try creating a separate page with the test table.
In your real test page you can include this page multiple times, after assigning values to the variables.

Related

It is possible to change the name of the generated variable when nesting regular URL mappings within a resource mapping?

In order to nest regular URL mappings within a resource mapping, according to the grails documentation in the url mapping section you can do the following
"/books"(resources: "book") {
"/publisher"(controller:"book", action:'publisher', method: "GET")
}
This will produce the following list of urls
Controller: book
| GET | /books/create | Action: create |
| GET | /books/${id}/edit | Action: edit |
| GET | /books/${bookId}/publisher | Action: publisher |
| POST | /books | Action: save |
| GET | /books | Action: index |
| DELETE | /books/${id} | Action: delete |
| PATCH | /books/${id} | Action: patch |
| PUT | /books/${id} | Action: update |
| GET | /books/${id} | Action: show |
As you can see the url generated by "/publisher"(controller:"book", action:'publisher', method: "GET") use the variable bookId instead of id like the other urls.
/books/${bookId}/publisher
My question is whether it is possible to change the name of this variable and name it for example id like the others
Thanks in advance
I have not used that mapping style personally but I believe the intent of the regular URL mapping within the resource mapping is to do something 'special' with that particular path, in this case /publisher (for example you could map it to a different controller altogether, etc)
It sounds like you want it to behave like another standard GET method, so you could add a resource entry like
get "/books/$id/publisher"(controller:"book", action:"publisher")

Slim tag inside another tag

I'm looking for cleaner solution, more Slim like, to write tag inside tag, this is what I have so far:
td = "#{p.created_at.to_formatted_s(:long)} <small>(#{time_ago_in_words(p.created_at)} ago)</small>".html_safe
Code above works fine - generate output I want, but doesn't look clean for me. I've tried rewrite it to eRuby
<td><%= p.created_at.to_formatted_s(:long) %> <small><%= time_ago_in_words(p.created_at) %> ago)</small></td>
And then convert it to Slim using Erb2Slim converter
td
= p.created_at.to_formatted_s(:long)
small
= time_ago_in_words(p.created_at)
| ago)
After that it doesn't show small tag and its content, any idea how and what is the best way to write above code in Slim?
Seems like you have a problem with indents (spaces). Try to use the following indents:
td
= p.created_at.to_formatted_s(:long)
|
small
| (
= time_ago_in_words(p.created_at)
| ago)
Note: in 3rd line 2 spaces needed after the pipe

Grails with Birt params

Ok, the example from plugin birt helped me tons, but one question is bothering me, how can I pass params to the birt to select from id?
question | description
----------------------
1 | blabla
2 | xoxoxo
3 | tititi
4 | buhbuh
Example: I have this table above... From my grails application, I choose what question I want, so if I choose 1,3,4... The Birt report shows me selected only.
Basically, I have to change my dataset too, because my query is static and needed to be dynamic:.
...(query) and a1.question_id = 1 and a2.question_id = 2 and and a3.question_id = 3 (query)...
But in grails how I will pass the params to dataset?
the Birt report receives the parameters with params, you can use this part of code
def options = birtReportService.getRenderOption(request, 'html')
def result=birtReportService.runAndRender(reportName, params, options)
render result
. Remember don't forget place your rptdesing in a folder on (web-app)

Can I make a scenario of RestFixture table in fitnesse?, or is there another way to make reusable components?

I have a working table:
#some javascript stuff
!define or { || }
#my stuff
!define headers { !-Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Accept: application/json -! }
|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://admin:password#localhost:5984/|
|setHeaders|${headers} |
|DELETE |/q-couch | | | jsonbody.ok ${or} jsonbody.error=="not_found" |
I now want to re-factor to make reusable component, and more readable test.
I tried this:
#what I hoped would be a reusable component.
|scenario|deletedb|name|
|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://admin:password#localhost:5984/|
|setHeaders|${headers} |
|DELETE|/#dbName | | |jsonbody.ok ${or} jsonbody.error=="not_found" |
#A more readable test
|Script|
|deletedb|q-couch|
When I press test I get The instance scriptTableActor. does not exist on every line in the scenario, within the script.
Is what I am doing valid? What am I doing wrong?
Why the error
The scriptTableActor. error occurs since you do not give a reference to any fixture in your script table header. Snipped from ScriptTable guide:
The first row is simply the word "Script" followed by the name and constructor arguments of the fixture (known as the "actor") that will be used by the rest of the table. If there is no actor specified then the previous script table's actor on this test page will be used.
The RestFixture has a special fixture for script tables, so your first row should be defined as:
|Script|RestScriptFixture|http://admin:password#localhost:5984/|
Reusable RestFixture components
I have used a structure of scenarios (defined in a ScenarioLibrary) and building blocks that we include to get reusable components. This strategy could also be used with other fixtures than RestFixture.
In your case I would had defined following scenarios
!|Scenario|When a |http_verb |is sent to |service |with headers set to |headers|
|setHeaders|#headers|
|#http_verb|#service|
!|Scenario|the response should contain |element |equal to |value |or |second_element |equal to |second_value|
|check|js|(response.jsonbody.hasOwnProperty('#element') && response.jsonbody.#element.toString()==#value)!-||-!(response.jsonbody.hasOwnProperty('#second_element') && response.jsonbody.#second_element.toString()==#second_value)|true|
The second scenario is a bit hefty, so a explanation could be in order. Since I do not know if ok and error always are returned in your response, first it checks whether the element exists or not with response.jsonbody.hasOwnProperty('#element') and then it checks if it has the correct value with response.jsonbody.#element.toString()==#value). I have escaped the or operator || with !--!.
The building block wiki would look like following:
|Script|RestScriptFixture|${server}|
|When a |delete |is sent to |${service} |with headers set to |${headers}|
|the response should contain |${element} |equal to |${value} |or |${second_element} |equal to |${second_value}|
And the test wiki would be:
!define TEST_SYSTEM {slim}
!define server {http://admin:password#localhost:5984/}
!define headers { !-Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Accept: application/json -! }
!define service {/q-couch/}
!define element {ok}
!define value {0}
!define second_element {error}
!define second_value {not_found}
!include PathTo.BuildingBlock
Some of the defines above, I probably would have put in the SetUp wiki.

How can I get array of model's methods names?

Is there a possibility in Rails/Ruby to get the list of model's methods.
fe. ModelName.methods
I want to get all names of methods that belongs to Mailer model.
Sorting methods out is always a problem in ruby, because you can't simply say : "give me methods specific to that class".
Getting methods for a specific class
You have to use array substraction like mentionned by #Monk_Code and even then, you can't separate methods from a base implementation and from its monkey patches.
To exhaustively remove all included modules and all parents methods :
> MyClass.instance_methods - ( MyClass.ancestors - [ MyClass ] ).map( &:instance_methods ).flatten
Replace #instance_methods with #methods if you want class methods.
Note that methods dynamically created with #define_method in parents like model callbacks will still appear, as they are defined directly on the child class.
Getting methods for a specific file
Often, isolating methods from a class is not enough.
I wrote an helper that helps me isolate methods from files. It allows to do that :
> MyModel.new.located_methods
+------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
| Name | Location |
+------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+
| ! | |
| <=> | /home/user/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/core.rb line 324 |
| unloadable | /home/user/.gem/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb line 245 |
| == | /home/user/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/core.rb line 296 |
| validates_format_of | /home/user/.gem/ruby/2.0.0/gems/activemodel-4.0.0/lib/active_model/validations/format.rb line 110 |
| and so on ... |
A first parameter allows to grep method names :
> MyModel.new.located_methods /validate/
+----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
| Name | Location |
+----------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
| _validate_callbacks | /home/user/.gem/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/core_ext/class/attribute.rb line 107 |
| _validate_callbacks= | /home/user/.gem/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/core_ext/class/attribute.rb line 117 |
| _validate_callbacks? | /home/user/.gem/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/core_ext/class/attribute.rb line 114 |
| validate_associated_records_for_amenities | /home/user/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/autosave_association.rb line 147 |
And a second one allows to grep per source file :
> MyModel.new.located_methods /validate/, /autosave/
+----------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| Name | Location |
+----------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| validate_associated_records_for_amenities | /home/user/.gem/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/autosave_association.rb line 147 |
the code
class Object
# Display an object methods list with their source location.
#
# List can optionally be filtered by method pattern and source file
# pattern.
#
# Mainly useful for debugging.
#
# #param [Regexp] method_pattern grep method name
# #param [Regexp] file_pattern grep file name
def located_methods( method_pattern = nil, file_pattern = nil )
list = ( method_pattern ? methods.grep( method_pattern ) : methods ).sort.map do |name|
location = method( name ).source_location
location = "#{location.first} line #{location.second}" if location
[ name.to_s.colorize( :yellow ), location ]
end
list = list.select { |meth| meth[1] =~ file_pattern } if file_pattern
puts ( [[ 'Name'.colorize( :yellow ), 'Location' ]] + list ).to_table( first_row_is_head: true )
true
end
end
This version depends on colorize and text-table, but you can easily modify it to use your preferred way of formatting.
class Object
def show_methods
(methods - self.class.superclass.instance_methods).sort
end
end
Mailer.show_methods
for example
I would suggest use the
show-method
from the pry gem.
You can also navigate within objects like in a unix console via
cd
ls
etc...
Check out this small example
and this: http://pryrepl.org/

Resources