theine icon indicating copy to clipboard operation
theine copied to clipboard

Capybara integration tests not working

Open BartlomiejSkwira opened this issue 11 years ago • 23 comments

Running model tests works, but when I try to run a Capybara/Poltergeist integration test I get exception:

An error occurred in an after hook
  Java::JavaLang::IllegalArgumentException: Object: #<struct Theine::Worker::InputProxy input=#<DRb::D
RbObject:0x329dffc4 @uri="druby://amberbox:60439", @ref=13816>> is not a legal argument to this wrappe
r, cause it doesn't respond to "read".
  occurred at org.jruby.util.IOInputStream.<init>(IOInputStream.java:63)


An error occurred in an after hook
  Java::JavaLang::IllegalArgumentException: Object: #<struct Theine::Worker::InputProxy input=#<DRb::D
RbObject:0x329dffc4 @uri="druby://amberbox:60439", @ref=13816>> is not a legal argument to this wrappe
r, cause it doesn't respond to "read".
  occurred at org.jruby.util.IOInputStream.<init>(IOInputStream.java:63)

/home/vagrant/.rvm/gems/jruby-1.7.4/gems/rspec-core-2.12.2/lib/rspec/core/example.rb:275 warning: sing
leton on non-persistent Java type Java::JavaLang::IllegalArgumentException (http://wiki.jruby.org/Pers
istence)

BartlomiejSkwira avatar Oct 17 '13 07:10 BartlomiejSkwira

Hm so it seems like you are using $stdin (or the methods that use it like gets) in the tests, or maybe Capybara is. I want to fix this, is it possible for you to provide a small example app I can use to reproduce this?

mrbrdo avatar Oct 17 '13 14:10 mrbrdo

I think I know how to fix this, but I still wonder why your test is using stdin. Could you show me the code of this after hook that is failing?

mrbrdo avatar Oct 17 '13 14:10 mrbrdo

Can you try the 0.0.10.rc1 version I just released?

gem uninstall theine
gem install theine -v "0.0.10.rc1"

You will probably get a different error or it will work.

mrbrdo avatar Oct 17 '13 16:10 mrbrdo

any luck?

mrbrdo avatar Oct 18 '13 14:10 mrbrdo

fixed in 0.0.10.

mrbrdo avatar Oct 20 '13 00:10 mrbrdo

Hm, there are still fails, but don't know what is the cause, the screen session closes immediately after the results are displayed. Any way to delay screen termination?

BartlomiejSkwira avatar Oct 20 '13 20:10 BartlomiejSkwira

Hm it's weird that it closes, that should be prevented by the read command here https://github.com/mrbrdo/theine/blob/master/lib/theine/server.rb#L32 You can try bundle open theine and try to put something else there that would prevent screen from closing, or modify the sh command parameters so the shell will not end after the command is complete. Let me know if you find a solution since I really want to prevent this.

mrbrdo avatar Oct 20 '13 20:10 mrbrdo

Also you can try https://blogs.oracle.com/samf/entry/smcup_rmcup_hate this will make it so that after the screen terminates you will still see the last output a little above. (note: I had to remove some backslashes from that code for it to work)

mrbrdo avatar Oct 20 '13 20:10 mrbrdo

PS: I was not able to reproduce not getting the exit prompt (Press [Enter] to exit...), when specs are failing or passing.

mrbrdo avatar Oct 20 '13 21:10 mrbrdo

Just released 0.0.11 which does this automatically (show output even after screen exits).

mrbrdo avatar Oct 20 '13 22:10 mrbrdo

https://blogs.oracle.com/samf/entry/smcup_rmcup_hate didn't help, but 0.0.11 works, I had also a problem with:

NameError: 
uninitialized constant Capybara::Screenshot

but moving capybara-screenshot above rspec/rails helped and tests pass.

Thanks for the support!

BartlomiejSkwira avatar Oct 21 '13 06:10 BartlomiejSkwira

That is great news. Is it possible to give more info about this capybara-screenshot problem? Is there something I can do in theine to avoid this being a problem or was it just a problem with your code?

mrbrdo avatar Oct 21 '13 06:10 mrbrdo

It was a problem of require order in spec_helper. Found this thread https://github.com/mattheworiordan/capybara-screenshot/issues/54 - other people had the same problem and they probably didn't use theine, so I think everything is good now.

BartlomiejSkwira avatar Oct 21 '13 06:10 BartlomiejSkwira

Actually I think there is a problem, when I move capybara-screenshot above rspec/rails there are no screenshots created, moving it down makes theine throw NameError. If you'd like to see my code I am working on https://github.com/amberbit/KarmaTracker and launching integration tests in spec/features

BTW: require order is a huge fail ... :/

BartlomiejSkwira avatar Oct 21 '13 10:10 BartlomiejSkwira

Just to confirm, when you run normally using rspec without theine it works fine?

mrbrdo avatar Oct 21 '13 18:10 mrbrdo

Yes

BartlomiejSkwira avatar Oct 22 '13 09:10 BartlomiejSkwira

just wanna let you know that I didn't forget about this, just need to find some time to get to it

mrbrdo avatar Oct 24 '13 10:10 mrbrdo

Sure, no worries, I'm also short on time.

BartlomiejSkwira avatar Oct 24 '13 10:10 BartlomiejSkwira

@BartlomiejSkwira can you please check if 0.0.13 changed anything? Using "theine rspec" or "theine rake spec" command.

Before it was using the development environment instead of test.

mrbrdo avatar Nov 28 '13 17:11 mrbrdo

Upgraded the gem to 0.013 and tried to use it with 2 jruby projects but I keep getting:

$ theine_server 
(spawn 11001)
Errno::ENOENT: No such file or directory - screen
         _spawn_internal at org/jruby/RubyProcess.java:1069
                   spawn at file:/home/../.rvm/rubies/jruby-1.7.6/lib/jruby.jar!/jruby/kernel19/process.rb:13
                   spawn at file:/home/../.rvm/rubies/jruby-1.7.6/lib/jruby.jar!/jruby/kernel19/kernel.rb:29
              add_worker at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/lib/theine/server.rb:32
  check_min_free_workers at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/lib/theine/server.rb:82
                     run at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/lib/theine/server.rb:127
              initialize at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/lib/theine/server.rb:23
                  (root) at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/lib/theine/server.rb:133
                 require at org/jruby/RubyKernel.java:1082
                 require at /home/../.rvm/rubies/jruby-1.7.6/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:73
                 require at /home/../.rvm/rubies/jruby-1.7.6/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:71
                  (root) at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/bin/theine_server:1
                    load at org/jruby/RubyKernel.java:1101
                  (root) at /home/../.rvm/gems/jruby-1.7.6@karmatracker/gems/theine-0.0.13/bin/theine_server:2
                    eval at org/jruby/RubyKernel.java:1121
                  (root) at /home/../.rvm/gems/jruby-1.7.6@karmatracker/bin/jruby_executable_hooks:15

BartlomiejSkwira avatar Nov 29 '13 11:11 BartlomiejSkwira

You probably need to install screen.

mrbrdo avatar Nov 29 '13 12:11 mrbrdo

Yeap sorry, forgot about screen in this env. The problem with capybara screenshot stayed: https://gist.github.com/BartlomiejSkwira/7718985

Jan If you'd like to launch the tests yourself clone https://github.com/amberbit/KarmaTracker and launch something from spec/features dir

BartlomiejSkwira avatar Nov 30 '13 13:11 BartlomiejSkwira

@BartlomiejSkwira I know this is very late, but I had some time to work on merging theine into spring (the official rails preloader). I wonder if that helps with your issue. I only tried it with JRuby 9.0.3.0, though. I think it should be enough to add gem 'spring-jruby' to your Gemfile, run bundle install and then run commands like spring rake test.

mrbrdo avatar Nov 17 '15 20:11 mrbrdo