diff options
| author | Zog | 2018-01-22 16:45:19 +0100 | 
|---|---|---|
| committer | Zog | 2018-02-09 10:21:45 +0100 | 
| commit | 8b6e358e3e59c507eac738a38b54f45a133164cc (patch) | |
| tree | d4e0fb10e2fddfc2643877e6234aaa76dc616450 /spec/support | |
| parent | d0f6b92c7cbf48fad205bb96b85d8305f80d13dc (diff) | |
| download | chouette-core-8b6e358e3e59c507eac738a38b54f45a133164cc.tar.bz2 | |
Refs #5669 @2h; Add a snapshot mechanism in the specs
Diffstat (limited to 'spec/support')
| -rw-r--r-- | spec/support/integration_spec_helper.rb | 7 | ||||
| -rw-r--r-- | spec/support/pundit/pundit_view_policy.rb | 7 | ||||
| -rw-r--r-- | spec/support/snapshot_support.rb | 23 | 
3 files changed, 36 insertions, 1 deletions
| diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 36306559d..a9a31f232 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -24,6 +24,13 @@ module IntegrationSpecHelper          context('', &block) if block_given?        end      end + +    def with_feature feature, &block +      context "with feature #{feature}" do +        let(:features){ [feature] } +        context('', &block) if block_given? +      end +    end    end    def self.included into diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 330209049..058f1f6ed 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -5,9 +5,14 @@ module Pundit        into.let(:current_referential){ referential || build_stubbed(:referential, organisation: organisation) }        into.let(:current_user){ create :user, permissions: permissions, organisation: organisation }        into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } +      into.let(:current_offer_workbench) { create :workbench, organisation: organisation}        into.before do          allow(view).to receive(:pundit_user) { pundit_user } - +        allow(view).to receive(:current_user) { current_user } +        allow(view).to receive(:current_organisation).and_return(organisation) +        allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench) +        allow(view).to receive(:has_feature?){ |f| features.include?(f)} +        allow(view).to receive(:user_signed_in?).and_return true          allow(view).to receive(:policy) do |instance|            ::Pundit.policy pundit_user, instance          end diff --git a/spec/support/snapshot_support.rb b/spec/support/snapshot_support.rb new file mode 100644 index 000000000..f1a6b1469 --- /dev/null +++ b/spec/support/snapshot_support.rb @@ -0,0 +1,23 @@ +RSpec::Matchers.define :match_actions_links_snapshot do |name| +  match do |actual| +    @content = Capybara::Node::Simple.new(rendered).find('.page_header').native.inner_html +    expect(@content).to match_snapshot(name) +  end + +  failure_message do |actual| +    out = ["Snapshots did not match."] +    expected = File.read(File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap") +    out << "Expected: #{expected}" +    out << "Actual: #{@content}" +    out << "\n\n --- DIFF ---" +    out << differ.diff_as_string(@content, expected) +    out.join("\n") +  end + +  def differ +    RSpec::Support::Differ.new( +        :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) }, +        :color => RSpec::Matchers.configuration.color? +    ) +  end +end | 
