remarkable-rb / remarkable

Simplifying tests!
http://www.nomedojogo.com/category/remarkable/
MIT License
121 stars 64 forks source link

Reimplement subject_attributes #9

Open hosh opened 14 years ago

hosh commented 14 years ago

Remarkable 3.3:

describe Post do
  subject_attributes { :title => "Post" }
  describe :title => "New Post" do
    it { should do_something }
  end
end

This does not exist in Remarkable 4.0.0.alpha1. Rspec2 has a metadata system that lets you do this:

describe Post, :extra_fields => whatever do describe "when pending", :pending => true end

describe "when focused", :focus => true
end

end

So there is some conflict with this system. At the minimum, subject_attributes would have to be implemented through metadata.

I've cut this out from Remarkable::ActiveRecord, but I'm noticing this is the heart of the Remarkable::Rails macros.

So folks, suggestions from people who use these features are definitely welcomed.

hosh commented 14 years ago

I think I found a solution. Instead of trying to override describe, I think introducing a new example-group level semantics would work:

describe Post do
  with_attributes :published => true do
    it { should act_in_a_different_way }
  end
end

While it adds to the namespace, I think that was where Rspec2 was going, with the pending example groups and metadata.

justinko commented 14 years ago

I like this much much better. I never used describe :title => 'Blah' because it felt dirty to use a method that overrides an RSpec core method.

I would, however, use with_attributes.

hosh commented 14 years ago

I've been playing with something like this with using only let() and Rspec2 metadata with Rack-level specs. https://gist.github.com/741657dae42ae9706672 It works pretty well.