diff --git a/features/its.feature b/features/its.feature index c53092b..58f4855 100644 --- a/features/its.feature +++ b/features/its.feature @@ -51,7 +51,7 @@ Feature: attribute of subject person end - its("phone_numbers.first") { should eq("555-1212") } + its("phone_numbers.first") { is_expected.to eq("555-1212") } end end """ diff --git a/lib/rspec/its.rb b/lib/rspec/its.rb index 4eb83ba..1685966 100644 --- a/lib/rspec/its.rb +++ b/lib/rspec/its.rb @@ -1,6 +1,14 @@ require 'rspec/its/version' require 'rspec/core' +# RSpec.deprecate < its_caller.first) + end + inner_subject.send(attr) end end @@ -175,6 +188,11 @@ def should_not(matcher=nil, message=nil) end RSpec.configure do |rspec| + + # Add RSpec configuration setting to allow + # the user to handle private method invoking warning + rspec.add_setting :its_raise_errors_for_private_method_calling + rspec.extend RSpec::Its rspec.backtrace_exclusion_patterns << %r(/lib/rspec/its) end diff --git a/spec/rspec/its_spec.rb b/spec/rspec/its_spec.rb index ebc59d5..df9eca7 100644 --- a/spec/rspec/its_spec.rb +++ b/spec/rspec/its_spec.rb @@ -1,5 +1,12 @@ require 'spec_helper' +# class RSpec::Core::Formatters::DeprecationFormatter +# Formatters.register self, :baem + +# def baem(notification) +# output << 'baem' +# end +# end module RSpec describe Its do describe "#its" do @@ -9,6 +16,37 @@ module RSpec its([]) { expect(described_class).to be Its } end end + + context "raises error when calling a private method" do + subject do + Class.new do + private + + def name + 'Maria' + end + + def self.name + 'Maria' + end + private_class_method :name + end + end + + before(:each) do + # expect(RSpec).to receive(:deprecate) + # .with('Testing private method name is deprecated', anything) + end + + context 'on an instance' do + its('new.name') { should eq('Maria') } + end + + context 'on a class' do + its('name') { should eq('Maria') } + end + end + context "with explicit subject" do subject do Class.new do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3433ee9..a7c9128 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,4 +12,8 @@ def method_missing(method, *args, &block) RSpec.configure do |config| config.run_all_when_everything_filtered = true config.order = 'random' + + # config.raise_errors_for_deprecations! + + # config.its_private_method_debug = true end