lib/rspectacular/plugins/authentication.rb in rspectacular-0.41.0 vs lib/rspectacular/plugins/authentication.rb in rspectacular-0.42.0

- old
+ new

@@ -26,30 +26,47 @@ klass.new else FactoryGirl.create(underscored_class_name.to_sym) end - authentication_method = if options.is_a?(Hash) && options[:authentication_method] + inferred_auth_method = if options.is_a?(Hash) && options[:authentication_method] options[:authentication_method] else :"authenticate_#{underscored_class_name}!" end described_class_instance = described_class.new - if described_class_instance.respond_to?(authentication_method, true) - described_class.skip_before_action authentication_method - elsif described_class_instance.respond_to?(:authenticate, true) - described_class.skip_before_action :authenticate + authentication_method = if described_class_instance.respond_to?(inferred_auth_method, true) + inferred_auth_method + elsif described_class_instance.respond_to?(:authenticate, true) + :authenticate + end + + if options[:status] == :unauthorized + described_class.send(:define_method, authentication_method) { false } + else + described_class.send(:define_method, authentication_method) { true } end - example.example_group_instance.class.let(current_class_method) { instance } + example.example_group_instance.class.let(current_class_method) do + if options[:status] == :unauthorized + nil + else + instance + end + end described_class.send(:define_method, current_class_method) do - instance + if options[:status] == :unauthorized + nil + else + instance + end end example.run described_class.send(:remove_method, current_class_method) + described_class.send(:remove_method, authentication_method) end end