Skip to content

Commit

Permalink
Enhance controller spec type setup
Browse files Browse the repository at this point in the history
No longer need to set up and pass in the stage variable, or manually set
the type when the specs are in the controllers folder.
  • Loading branch information
lexun committed Apr 26, 2015
1 parent 94a5893 commit 8e93c76
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
5 changes: 1 addition & 4 deletions spec/lib/launchpad/gui/controllers/main_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'spec_helper'

describe Launchpad::MainController, type: :controller do
subject { described_class.new stage: stage_double }

let(:stage_double) { double 'stage', on_shown: true }
describe Launchpad::MainController do

before { allow(Launchpad::UpdateManager).to receive :new }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'spec_helper'

describe Launchpad::OptionsController, type: :controller do
subject { described_class.new stage: stage_double }

let(:stage_double) { double 'stage', on_shown: true, close: true }

describe Launchpad::OptionsController do
let(:options) do
[:install, :local_index_path, :remote_index_uri, :login_server, :port]
end
Expand Down
16 changes: 7 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
require 'pry' unless ENV['CI']
require 'launchpad'
require 'rspec'
require 'support'

RSpec.configure do |config|
# Exit the javafx toolkit after running specs
config.after(:suite) { JavaFXImpl::PlatformImpl.tkExit }

# Remove jrubyfx controller overrides and set the stage double
config.before(:example, type: :controller) do
described_class.define_singleton_method(:new) do |*args|
allocate.tap do |controller|
stage = args.last && args.last[:stage]
controller.instance_variable_set(:@stage, stage) if stage
controller.send :initialize
end
end
# Set type to controller for all specs in the controllers folder
config.define_derived_metadata(file_path: /controllers/) do |metadata|
metadata[:type] ||= :controller
end

# Include the controller shared context for all controller specs
config.include Launchpad::RSpec::Controller, type: :controller
end
1 change: 1 addition & 0 deletions spec/support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dir.chdir('spec') { Dir['support/**/*.rb'].each { |file| require file } }
17 changes: 17 additions & 0 deletions spec/support/controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Launchpad
module RSpec
# Remove the jrubyfx controller overrides and set the stage double.
module Controller
extend ::RSpec::SharedContext

let(:stage) { double 'stage', on_shown: true, close: true }

subject do
described_class.allocate.tap do |controller|
controller.instance_variable_set :@stage, stage
controller.send :initialize
end
end
end
end
end

0 comments on commit 8e93c76

Please sign in to comment.