3

So I'm working on the EdX part 2 homework 1, and I cannot seem to get save_and_open_page working.

Here's the rspec chunk:

    describe 'merge action' do

  before do
    @article_for_merging = Factory(:article)
    @article_for_merging.body = 'something we will merge'
  end

  it 'should merge articles' do
    get :merge, 'id' => @article.id, 'merge_with' =>  @article_for_merging.id
    response.should render_template('new')
    assigns(:article).should_not be_nil
    assigns(:article).should be_valid
    response.should contain(/body/)
    response.should contain(/extended content/)
    save_and_open_page
    debugger
    response.should have_field('article[body]',:with => @article.body + @article_for_merging.body)
    response.should have_selector('form#merge input#merge_with')
    response.should have_selector('form#merge input#merge')
  end
end

Other stack overflow posts suggest solutions:

RSpec2 and Capybara

http://paikialog.wordpress.com/2012/02/11/webrat-no-such-file-to-load-action_controllerintegration/

save_and_open_page (capybara / launchy) stopped working in a project - error

and I believe I have tried all, but I cannot get it to work. It's frustrating because I can view the raw HTML but with big pages it's such a pain to ferret out the html details I need - looking in browser with things like chrome's "inspect element" is SO much easier.

Whatever combination of suggested solutions I've tried I keep coming back to some variation on this error:

 1) Admin::ContentController with admin connection merge action should merge articles     Failure/Error: save_and_open_page     LoadError:       no such file to load -- action_controller/integration     # ./spec/controllers/admin/content_controller_spec.rb:498:in `block (4 levels) in '

Any help very much appreciated

Community
  • 1
  • 1
Sam Joseph
  • 4,584
  • 4
  • 31
  • 47

2 Answers2

2

ah, I think this might have fixed it:

http://paikialog.wordpress.com/2012/02/11/webrat-no-such-file-to-load-action_controllerintegration/

Sam Joseph
  • 4,584
  • 4
  • 31
  • 47
  • hmm, seems I have to use 'visit' rather than get, but then that doesn't play well with the rest of the specs from typo – Sam Joseph Nov 22 '12 at 20:46
  • 1
    oh well I hacked my own solution: File.open('/tmp/test.html','w'){|file| file.write(response.body)} `firefox '/tmp/test.html'` – Sam Joseph Nov 23 '12 at 06:03
1

Working from Sam Joseph's hacked solution in the comments, I wrote this method and put it in spec/support/helpers.rb:

def save_and_open_rspec_page
  File.open('/tmp/test.html','w'){|file| file.write(rendered)}; `open '/tmp/test.html'`
end

response.body didn't work for me, presumably because I'm in a view spec?

firefox didn't work for me either. Since I'm on a Mac, I used open instead.

Also, I called render before save_and_open_rspec_page on my view spec.

Community
  • 1
  • 1
webdevguy
  • 975
  • 10
  • 17