From 2ee2fe494da7fd086dd34c8aebdfc0448e102067 Mon Sep 17 00:00:00 2001 From: erwanlr Date: Mon, 25 Mar 2013 13:53:36 +0100 Subject: [PATCH] WpItem::Findable#Found_From= specs --- lib/common/models/wp_item/findable.rb | 5 ++-- spec/lib/common/models/wp_item_spec.rb | 1 + .../wp_item_findable_found_from.rb | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 spec/shared_examples/wp_item_findable_found_from.rb diff --git a/lib/common/models/wp_item/findable.rb b/lib/common/models/wp_item/findable.rb index 6b500f84..4d440bff 100755 --- a/lib/common/models/wp_item/findable.rb +++ b/lib/common/models/wp_item/findable.rb @@ -3,10 +3,9 @@ class WpItem attr_reader :found_from - #def allowed_options; super << :found_from end - def found_from=(method) - @found_from = method[%r{find_from_(.*)}, 1].gsub('_', ' ') + found = method[%r{find_from_(.*)}, 1] + @found_from = found.gsub('_', ' ') if found end module Findable diff --git a/spec/lib/common/models/wp_item_spec.rb b/spec/lib/common/models/wp_item_spec.rb index c3e844df..a869bdd4 100644 --- a/spec/lib/common/models/wp_item_spec.rb +++ b/spec/lib/common/models/wp_item_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe WpItem do it_behaves_like 'WpItem::Existable' + it_behaves_like 'WpItem::Findable#Found_From=' subject(:wp_item) { WpItem.new(uri, options) } let(:uri) { URI.parse('http://example.com') } diff --git a/spec/shared_examples/wp_item_findable_found_from.rb b/spec/shared_examples/wp_item_findable_found_from.rb new file mode 100644 index 00000000..ae124aab --- /dev/null +++ b/spec/shared_examples/wp_item_findable_found_from.rb @@ -0,0 +1,23 @@ +# encoding: UTF-8 + +shared_examples 'WpItem::Findable#Found_From=' do + + describe '#found_from=' do + after do + subject.found_from = @method + subject.found_from.should == @expected + end + context 'when the pattern is not found' do + it 'returns nil' do + @method = 'I_do_not_match' + @expected = nil + end + end + + it 'replaces _ by space' do + @method = 'find_from_some_detection_method' + @expected = 'some detection method' + end + end + +end