I have just realized (after several WHY?!) that stubbing is not helpful
here because we are testing an executable which is of course run by another
Ruby interpreter. It simply does not know anything about the stubs.
I see relying on actual default instance and actually supported algorithms
as the only option. It is not bad since this is acceptance test for our
application, not unit test. Of course I can avoid calling Executable and do
some magic to call cli directly and make it looking as if it was command
line call but it kinda ruins the idea of an acceptance test and makes the
test itself way too complicated.

On Monday, May 26, 2014, Mikael Muszynski <notifications@github.com> wrote:

> In spec/features/user_provides_invalid_flags_spec.rb:
>
> > @@ -9,4 +9,16 @@
> >        expect(executable.error).to match(/invalid option/)
> >      end
> >    end
> > +
> > +  context 'with -a flag without an algorithm' do
> > +    it 'exits with exit code "64" and prints list of available algorithms' do
> > +      executable = Executable.run('-a')
> > +
> > +      expect(executable.exit_code).to eq 64
> > +
> > +      error_lines = executable.error.split("\n")
> > +      expect(error_lines[2]).to match(/please use one of the following algorithms:/i)
> > +      expect(error_lines[3..-1]).to eq BlueCherries::AlgorithmFinder::ALGORITHMS.keys
>
> On line 19 here you're making an assumption about the fact that the line
> is splittable on newlines, and then you're putting expectations on exact
> lines (or ranges of lines).
>
> I think that it would be better if you were much looser in your
> expectations about what comes out as an error, since we're only trying to
> verify that the available algorithms are shown to the user (and that a
> certain exit code is used).
>
> I'm also thinking that if stub whatever it is that provides the list of
> algorithms, then we couldn't need to call external classes to get that list.
>
> I'm thinking this could all be written something like this:
>
> algorithm_list = %w[foobar bazquux banana]AlgorithmFinder.stub(:available_algorithms).and_return(algorithm_list)
> executable = Executable.run('-a')
> expect(executable.exit_code).to eq 64algorithm_list.each do |algorithm_name|
>   expect(executable.error).to match(/#{algorithm_name}/)end
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/linduxed/bluecherries/pull/29/files#r13054665>
> .
>


-- 
Sergey Zubtsovskiy
sergey.zubtsovskiy@gmail.com
Skype: szubtsovskiy