FINRAOS / MSL

MSL (pronounced 'Missile') stands for Mock Service Layer. Our tools enable quick local deployment of your UI code on Node and mocking of your service layer for fast, targeted testing.
http://finraos.github.io/MSL/
Apache License 2.0
32 stars 24 forks source link

ruby msl-client not changing anything. #76

Closed aaronhumerickhouse closed 9 years ago

aaronhumerickhouse commented 9 years ago

I don't know if I'm using this correctly, but how am I supposed to run MSL on a port that's already used?

What I've been trying is: Starting msl-server node_modules/msl-server/bin/msl --port=8001 --debug=true Starting my app on 3082 Running a Test

RSpec.describe 'Tournament Settings Overview' do
  before :all do
    @browser = Watir::Browser.new(:firefox)
    @root = 'http://localhost:3082'
    @browser.goto @root

    @browser.text_field({id: 'user_login'}).set 'user'
    @browser.text_field({id: 'user_password'}).set 'password'
    @browser.button({name: 'commit'}).click
  end

  it 'is overridden by msl' do
    configurations = {}
    configurations['requestPath'] =  "#{@root}/api/tournaments/54e4c2bb29de79199e0074de" #<=Adding root is the only way I see to point it at the correct port, otherwise if I start msl-server up on this port, there's a conflict.
    configurations['responseText'] = '{"id":"54e4c2bb29de79199e0074de","name":"test 1234","short_name":"test asdf","abbrev":"TSTSDF","start_date":"2015-02-27","end_date":"2015-02-28","sport_id":26,"program_id":null,"program_name":null,"created_at":"2015-02-18T16:50:03Z","description":null,"org_id":7601,"primary_venue_id":null,"timezone":"America/Chicago","dst":null,"time_format":null,"current_season_id":"54e4c2bb29de79199e0074df","microsite_settings":{"standings":true,"schedule":true,"brackets":true,"seed_ranks":true,"auto_publish":true},"season_id":"54e4c2bb29de79199e0074df"}';
    configurations['contentType'] = 'application/json'
    configurations['eval'] = 'function (req,responseText) { return "[" + responseText + "]"; }'
    configurations['statusCode'] = '200'
    configurations['delayTime'] = '0'

    # Actually make the call  to register this information.
    setMockRespond('localhost', 8001, configurations.to_json)

    @browser.goto("#{@root}/tournaments/54e4c2bb29de79199e0074de/settings");

    expect(@browser.element({id: 'tournament-54e4c2bb29de79199e0074de-name'}).value).to eq "test 1234"
  end

  after :all do
    @browser.quit
  end
end
JacobSheppard commented 9 years ago

You can't have two applications listening to the same port. So what you’ll need to do is make all calls made by the app to point to ‘localhost:8001’.

Right now while ‘@root’ is ‘localhost:3082’,without a proxy or anything, there is no way for the MSL server to receive the call. After you make that change, the requestPath should just be '/api/tournaments...'.

Another solution would be to 'run' the app on MSL. Have the MSL server serve up all needed responses through local file system, registered responses, or responses generated using the extension file. So start MSL on port 8001 still and just have root as 'http://localhost:8001/index.html'.

Let me know if that helps.

kood1 commented 9 years ago

The app in this case refers to your front-end code only. The idea is that you build your front-end code and deploy it locally on the local file system (for example using grunt). Then have MSL server host those front-end code so that you can open up the html via http://localhost:8001/yourhtml.html. This way, when the front-end code makes a server-side call such as "/myapp/myservice" (which is http://localhost:8001/myapp/myservice), MSL server can respond with a mock response.

aaronhumerickhouse commented 9 years ago

Thank you.