Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • C chouette-core-tmp
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Administrator
  • chouette-core-tmp
  • Wiki
  • Rails spec

Rails spec · Changes

Page history
Rails spec: Translate to English authored Apr 03, 2018 by Teddy Wing's avatar Teddy Wing
Hide whitespace changes
Inline Side-by-side
Showing with 19 additions and 16 deletions
+19 -16
  • Rails-spec.md Rails-spec.md +19 -16
  • No files found.
Rails-spec.md
View page @ 2f8cff1a
# Ecriture de fichier spec
# Guidelines for writing a spec file
## Spec de `Model`
## Spec de `View`
## Model spec
## View spec
### Helpers
- _matcher_ `have_link_for_each_item` qui permet d'itérer sur tous les éléments d'une collection, et de vérifier - pour chacun - qu'on a un lien vers l'URL désirée (dans [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
- _matcher_ `have_the_right_number_of_links` qui permet d'itérer sur tous les éléments d'une collection, et de vérifier - pour chacun - qu'on a le bon nombre de liens (dans [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
- `with_permission permission_name do ...` qui permet de tester le rendu avec un utilisateur disposant de la permission désirée (dans [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
- `build_paginated_collection(:factory_name, decorator_class, factory_options, context: decorator_context)` permet de construire une collection d'objets et de les décorer, de façon similaire à ce que ferait un controlleur (dans [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22).
- _matcher_ `have_link_for_each_item` checks that each item in the given collection has a link to the expected URL (defined in [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
- _matcher_ `have_the_right_number_of_links` checks that each item in the given collection has the expected number of links (defined in [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
- `with_permission PERMISSION_NAME do ...` a context manager that enables view testing with the given permission activated (defined in [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
- `build_paginated_collection(:factory_name, decorator_class, factory_options, context: decorator_context)` creates a collection of decorated objects using factories, with a result similar to what would be created in the controller (defined in [`spec/support/integration_spec_helper.rb`](http://github.com/af83/stif-boiv/blob/f83df1a0b39b2af7d3088db9c98365c4088bc021/spec/support/integration_spec_helper.rb#L22)).
### Tips
- pour _nester_ la vue, par exemple émuler une URL `/parents/:parent_id/objects`: `controller.request.path_parameters[:parent_id] = parent.id`
- to simulate a nested route (for example, `/parents/:parent_id/objects`):
### Exemple
controller.request.path_parameters[:parent_id] = parent.id
Pour une vue d'__index__, dans laquelle on veut vérifier:
- le nombre de lignes du tableau
- la présence de lien pour chaque ligne (en fonction des permissions)
### Example
Here's an example `index` view spec, where we want to verify:
- the number of rows in the table
- that each row has a link (accounting for permissions)
```ruby
require 'spec_helper'
......@@ -59,14 +62,14 @@ describe "/objects/index", :type => :view do
end
```
## Spec de `Controller`
## Controller spec
### Helpers
- `login_user` pour créer un utilisateur et le passer dans la session
- `with_permission permission do ...` pour ajouter la permission à l'utilisateur connecté dans le contexte
- `login_user` to create a `User` and authenticate it in the session
- `with_permission PERMISSION do ...` to add the given permission to the current user in the context of the block
### Exemple
### Example
```ruby
RSpec.describe ObjectController, :type => :controller do
......
Clone repository
  • Class Diagram
  • Data Models
  • Home
  • Optional Features
  • Rails Controller
  • Rails I18n
  • Rails migrations
  • Rails models
  • Rails spec
  • Rails views
  • Seed database