On Tue, Mar 19, 2013 at 9:52 AM, Perry Smith <pedz...@gmail.com> wrote:
>
> On Mar 19, 2013, at 10:41 AM, David Chelimsky wrote:
>
>> On Tue, Mar 19, 2013 at 7:20 AM, Иван Неверов <ivan.neve...@gmail.com> wrote:
>>> Hi all
>>> Could somebody tell me, is it possible to assign some tag=>value to all
>>> examples in directory?
>>>
>>> Like I want to mark all tests in spec/unit as :type=>'shallow'. And have
>>> some tests in other directory also with type shallow (assigned in describe)
>>> And then filter them with -t type:shallow
>>>
>>>
>>> Thanks
>>> Ivan
>>
>> Unfortunately, there's nothing built in to support this. I'd recommend
>> you submit a feature request to
>> http://github.com/rspec/rspec-core/issues.
>
> I do this:
>
>     config.include RSpec::Rails::ViewExampleGroup, type: :presenter, 
> example_group: {
>       file_path: config.escaped_path(%w[spec presenters])
>     }
>
> and it appears to work for me.  But David would know better than I.
>
> Am I fooling myself somehow?  Or did I misunderstand the question?

Actually that does point to a solution. The trick is the OP wants to
add a tag to the groups in that directory so that those examples can
be filtered, which means it has to be added _before_ filtering
happens. I hadn't thought there was a good way to do this, but your
example reminded me there is, sort of. The caveat is that this is a
bit magical and relies on a somewhat buried API that may or may not be
supported in the long term. That said, for now you _can_ do this:

module ShallowExampleGroup
  def self.included(host)
    host.metadata[:type] = 'shallow'
  end
end

RSpec.configure do |config|
  config.include ShallowExampleGroup, example_group: {
    file_path: config.escaped_path(%w[spec unit])
  }
end

HTH,
David
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to