On Jan 29, 10:38 pm, [email protected] wrote:
> It seems that going forward 'its' is gonna be deprecated.
> I would like to know what is the best way to replicate its behaviour.
>
> For instance I have this:
>
>  context 'new article' do
>        subject(:article) { Article.new }
>        its(:for_magazine?) { should be_false }
>        its(:total_pages) { should == 1 }
>        its(:current_page_number) { should == 1 }
>        its(:has_next_page?) { should be_false }
> end
>
> if I change to somethig like
>  it { expect(article.for_magazine?).to be false }
>
> it prints out   'new article'  should be false
> Which makes no sense
>
> if I do
>
>  context "for magazine?" do
>     it …..
>  end
>
> prints well but is very verbose
>
> is there any other alternative?

Here's what I wrote about `its` recently when asked on Twitter about
it:

https://gist.github.com/4503509

There's already a gem that provides `its` plus some additional
features:

https://github.com/dnagir/its

...so you're welcome to use that if you feel like you need this
feature.

As for how I'd approach this without using `its`...that's hard to say
without seeing the bigger picture of what the behavior of `Article` is
and what role it plays in your system.  I might do something like
this, though:

describe Article do
  context 'when instantiated with no arguments' do
    it 'is not for a magazine' do
      expect(Article.new).not_to be_for_magazine
    end

    it 'has only one page' do
      article = Article.new
      expect(article.total_pages).to eq(1)
      expect(article.current_page_number).to eq(1)
      expect(article).not_to have_next_page
    end
  end
end

Maximizing terseness is not one of the primary things I aim for when I
write specs.

HTH,
Myron

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to