-
-
Notifications
You must be signed in to change notification settings - Fork 760
Conversation
I think it's time to extract I can see why this is a logical extension of I'm going to leave this open as I think it does make sense in the context of the other |
I agree with David. Personally I rarely use one liners like that, and I didn't even know about its until now. its(:length) {should == 3} seems somewhat readable and marginally useful. but just doesn't seem to be either to me. But that's just one man's opinion. |
I actually agree, even though I submitted the patch. I didn't even expect that much response, and I'm not sure it's super readable. It just was the natural extension of the usage that grows out of subject and its. It was also driven by trying to come up with some more functional option for testing methods than the ivar/global shuffle that comes out of before, let, and subject. |
And it didn't seem much worse than its([:key]) or its('foo.bar') ;). |
@timocratic - no, it didn't seem much worse than either of those, but both of those made my stomach a little ill. I accepted them because they seemed to align w/ the intent of |
I agree. Maybe it was time for the straw that broke the camels back. Maybe it is time for an abstracted out its/calling functionally lib. Sort of shoulda or the subject. |
I have no idea what |
I agree it's not a great syntax, it is more exploratory of where the logical limit of its([:key]) is as useful. And if you have a 50 tests that fit in one page full of it{}, its(){} you suddenly want to handle the method call case better. Maybe some of the magic its could be abstracted into something else with even more magic, that would allow things like it.method_name(5) { should}. or some other method for fp style testing - I've experimented with setting subject to a lambda so I could subject.call(), and that wasn't any better, but solved a similar use case. |
I'm closing this as its definitely something I don't want in rspec-core, but feel free to keep the conversation going about extracting |
I found this thread when looking for this functionality. I tend to agree: in many cases it won't make a lot of sense, however my use case reads quite well:
|
I also found this thread while searching for this functionality. My current implementation is getting a bit wordy. In my case it reads better to be able to pass an argument: describe '#conditions_apply_to?' do
let(:product){ Fabricate :product }
context 'when combining with other conditions' do
before { subject.conditions_combination_operator = 'and' }
it 'returns false' do
subject.conditions_apply_to?(product).should be_false
end
end
end versus... describe '#conditions_apply_to?' do
let(:product){ Fabricate :product }
context 'when combining with other conditions' do
before { subject.conditions_combination_operator = 'and' }
its(:conditions_apply_to?, product){ should be_false }
end
end Has this feature ever been implemented? Or have you thought of a better practice that you would recommend as an alternative to people searching for this feature? |
No. http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3#core__will_be_moved_into_an_external_gem Whoever maintains that may choose to implement something like this.
I recommend calling the method with arguments: it '<describe your behavior>' do
subject.conditions_combination_operator = 'and'
expect(subject.conditions_apply_to?(product)).to be_false
end |
I agree. Already As much as is possible, invoking your code in a test should reflect how it is used in the "real world" |
Fair enough. Implementing this could get ridiculous if, for example, the method took a block argument.
|
Thanks @myronmarston You helped me realize that my desire for an describe '#conditions_apply_to?' do
let(:product){ Fabricate :product }
it 'returns false when combining with other conditions' do
subject.conditions_combination_operator = 'and'
expect(subject.conditions_apply_to?(product)).to be_false
end
end |
Allow passing of arguments into 'its'
its(:at, 1) { should == 'b' }
cukes and specs included