diff options
| author | Zog | 2017-12-15 17:01:49 +0100 | 
|---|---|---|
| committer | Zog | 2017-12-19 17:02:37 +0100 | 
| commit | 2736ff5e010586266176a9a0fb0ac8dc6e227f63 (patch) | |
| tree | e078978c768137edaaeb17843a28f97392c87072 /spec/support | |
| parent | 84739968d68c561f6317b9fa21a476dc0dcb240b (diff) | |
| download | chouette-core-2736ff5e010586266176a9a0fb0ac8dc6e227f63.tar.bz2 | |
Ref #5291@2h; Specs setup
- Refactor specs helper to be more generic
- Write missing specs for the Workbenches#show view
We now have failing tests highlighting the bug
Diffstat (limited to 'spec/support')
| -rw-r--r-- | spec/support/integration_spec_helper.rb | 30 | 
1 files changed, 30 insertions, 0 deletions
| diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 182cadf24..5bcf0bd3a 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -4,9 +4,39 @@ module IntegrationSpecHelper        let(:permissions){ [permission] }        context('', &block) if block_given?      end + +    def paginate_collection klass, decorator, page=1 +      ModelDecorator.decorate( klass.page(page), with: decorator ) +    end + +    def build_paginated_collection factory, decorator, opts={} +      count = opts.delete(:count) || 2 +      page = opts.delete(:page) || 1 +      klass = nil +      count.times { klass ||= create(factory, opts).class } +      paginate_collection klass, decorator, page +    end    end  end  RSpec.configure do |config|    config.extend IntegrationSpecHelper, type: :view  end + +RSpec::Matchers.define :have_link_for_each_item do |collection, name, href| +  match do |actual| +    collection.each do |item| +      expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a[href='#{href.call(item)}']", count: 1) +    end +  end +  description { "have #{name} link for each item" } +end + +RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| +  match do |actual| +    collection.each do |item| +      expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a", count: count) +    end +  end +  description { "have #{count} links for each item" } +end | 
