Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Modifying pact-consumer-js-dsl to work with both Nodejs and Web projects #27

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b4b062a
fixing gulp startup of pact-mock-service; adding more logging around …
Jan 29, 2015
be089e9
committing better bower file, registered pact-consumer-js-dsl to bower
Jan 29, 2015
65c5632
moving example to example/web to give space to create nodejs example;…
Jan 29, 2015
a4fc3fb
changing rc2 to rc1, since rc2 went missing
Jan 29, 2015
b3e4251
Wrapping Pact in UMD so that it can be used for web, requirejs or Nod…
Feb 2, 2015
cc1a2ea
Adding back Gemfile
Feb 2, 2015
933b3e0
removing node prefix/suffix, fixing some paths pointing to the other …
Feb 2, 2015
1714620
fixing example to use mockService instead of provider variable
Feb 2, 2015
a18d954
merging latest upstream to UMD changes. Fixed some part of code that…
Feb 4, 2015
3ca2d25
updating pact-mock-service to 0.2.4, updating readme/contributing, ad…
Feb 4, 2015
dd23677
fixing merge issues, again
mboudreau Feb 4, 2015
2a3689f
updating npm requirement for the node example.
Feb 5, 2015
9f8ad2c
removing the requirement for a done function as it's not entirely nee…
Feb 5, 2015
62015d7
changing mockService to show a few more public functions, changing th…
Feb 9, 2015
473df4e
Merge branch 'master' of github.com:mboudreau/pact-consumer-js-dsl
Feb 9, 2015
b85108f
removing old bootstrap file, not needed, recreating distribution file
Feb 9, 2015
074ea22
adding main property again, dunno where it went.
Feb 9, 2015
ea7ece9
removing the need for global command within doco
Feb 12, 2015
95b25be
fixing the PR as per beth's comments. Reverting the optional done fu…
Feb 17, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

47 changes: 37 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,60 @@

### Prepare development environment

#### Nodejs

You need to install nodejs in your computer.

In Mac OS X:

$ brew install node
$ export PATH=$PATH:/usr/local/share/npm/bin
$ source .bash_profile

In Linux:

### To start development
$ apt-get install nodejs

In Windows: [Download the 32-bit version of Nodejs installer.](http://nodejs.org/download/)

You need to install grunt-cli, bower and karma first
#### Installing Ruby

$ npm install -g grunt-cli bower karma
In Mac OS X:

Inside the project folder, simply run `npm install` and `bundle install` to install the other dependencies.
$ brew install ruby
$ export PATH=$PATH:/usr/local/opt/ruby/bin
$ source .bash_profile

In Linux:

### During Development
$ apt-get install ruby1.9.3 rubygems

In Windows: [Follow the installation instructions here to install Ruby and RubyGems](https://github.com/bethesque/pact-mock_service/wiki/Installing-the-pact-mock_service-gem-on-Windows)

To run gulp tasks:
#### Installing Bundle & pact-mock-service

$ gulp
Run the following commands (works in all OS'):

$ gem i bundler

### To start development

You need to install gulp, bower and karma to build and test the code; if you don't want them to be globally available, remove the `-g` at the end:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that installing gulp, bower and karma as global or local is the user's choice, is it not? There's nothing in the pact dsl that requires them to be global is there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, just makes it easier to run things. I guess I can change that.

$ npm install gulp bower karma -g

While inside the project folder, setup the dependencies needed by running:

or if you don't want to install the gulp-cli globally:
bundle install
npm install
bower install

$ node_modules/.bin/gulp run-tests
To build and test:

$ gulp

Useful gulp tasks:
- `gulp build` creates the distribution version of the code, which sits in the 'dist' folder.
- `gulp run-tests` will build the distribution file, spin up the pact server and run the tests in a browser and in nodejs.
- `gulp watch` will spin up the pact server and automatically rerun the tests in a browser every time a relevant file is changed.

Expand All @@ -42,7 +69,7 @@ Useful gulp tasks:

The `pact-consumer-js-dsl.js` is a minified and concatenated version of the Pact Javascript source. In order to generate it just run...

$ gulp
$ gulp build

### Release process

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source 'https://rubygems.org'
gem 'pact-mock_service', '~> 0.2.3.pre.rc1'
gem 'pact-mock_service', '~> 0.2.4'
35 changes: 18 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ GEM
awesome_print (1.6.1)
diff-lcs (1.2.5)
find_a_port (1.0.1)
json (1.8.1)
pact-mock_service (0.2.3.pre.rc1)
json (1.8.2)
pact-mock_service (0.2.4)
find_a_port (~> 1.0.1)
json
pact-support (~> 0.1.1)
pact-support (~> 0.2.1)
rack
rack-test (~> 0.6.2)
rspec (>= 2.14)
term-ansicolor (~> 1.0)
thor
webrick
pact-support (0.1.3)
pact-support (0.2.1)
awesome_print (~> 1.1)
find_a_port (~> 1.0.1)
json
Expand All @@ -25,21 +25,22 @@ GEM
term-ansicolor (~> 1.0)
thor
rack (1.6.0)
rack-test (0.6.2)
rack-test (0.6.3)
rack (>= 1.0)
randexp (0.1.7)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.0)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rspec-support (~> 3.2.0)
rspec-mocks (3.2.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
Expand All @@ -50,4 +51,4 @@ PLATFORMS
ruby

DEPENDENCIES
pact-mock_service (~> 0.2.3.pre.rc1)
pact-mock_service (~> 0.2.4)
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ This DSL relies on the Ruby [pact-mock_service][pact-mock-service] gem to provid
* Google users group: https://groups.google.com/forum/#!forum/pact-support
* Twitter: [@pact_up](https://twitter.com/pact_up)

### Getting Started (with Karma, Jasmine and the pact-mock_service gem)
### Installing pact-mock-service

1. Install the [pact-mock_service](https://github.com/bethesque/pact-mock_service) ruby gem
* If on Windows, please refer to the [Installing pact-mock-service on Windows](https://github.com/bethesque/pact-mock_service/wiki/Installing-the-pact-mock_service-gem-on-Windows) *

The easiest way is to add `gem 'pact-mock_service', '~> 0.2.3.pre.rc1'` to your `Gemfile` and run `bundle install`
1. You must install [Ruby](https://www.ruby-lang.org/en/downloads/) and [RubyGems](https://rubygems.org/pages/download) first.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have multiple versions of the gem installed, and you omit the Gemfile and bundle exec, then you may not get the gem version you expect. It is not good Ruby practise to use a gem without a Gemfile. Can you put that back in please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bethesque I added the Gemfile back in, but I'm leaving the README how it is. It might be good Ruby practice, but this isn't for people that write Ruby. As of yet, I haven't had the need of more than one version of pact-mock-service.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's like me claiming that I don't need to follow good node practice because I'm not a node developer :P
The problems caused by not using Gemfiles and bundle exec happen to people who write Ruby, and people who don't write Ruby. When they happen to people who don't write Ruby, then it's even harder for them to diagnose the cause. If there is a backwards incompatible change to the mock server, and you upgrade one project but not another, then one of your projects is going to break.


1. After these binaries as available in the console, you can install the mock service easily using this command: `gem i pact-mock_service -v 0.2.4` * Windows users must run this command after following Wiki instructions *

### Getting Started (with Karma, Jasmine and pact-mock-service)

1. Install and configure Karma with Jasmine

Expand All @@ -25,18 +29,19 @@ This DSL relies on the Ruby [pact-mock_service][pact-mock-service] gem to provid
1. Install Karma using their [installation instructions](http://karma-runner.github.io/0.12/intro/installation.html)

This basically consists of running,

* `npm install karma --save-dev`
* `npm install karma-jasmine karma-chrome-launcher --save-dev`
* `npm install -g karma-cli`

```
npm install karma karma-jasmine karma-chrome-launcher --save-dev
npm install -g karma-cli
```

1. Initialise and configure Karma

Run `karma init`. Answer **jasmine** for *testing framework* and **no** for *use require.js*.

1. Add `pact-consumer-js-dsl` to your project by running `npm install DiUS/pact-consumer-js-dsl#X.Y.Z --save-dev`, where `X.Y.Z` is the latest stable version, according to the [releases][releases] page.
1. Add `pact-consumer-js-dsl` to your project by running `bower install pact-consumer-js-dsl --save-dev`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about people who are using npm without bower? I would have thought npm was a more consistent common denominator? (Not being a javascript person, I can't really comment though).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bethesque If you're using Karma, it would need to use the web version, and not the node version . For web libraries, you use Bower, for Node libraries you use npm. It's not a hard rule, but either way, with the new UMD wrapping, they both work.

1. Tell Karma about `pact-consumer-js-dsl.js` in `karma.conf.js`. In the `files: []` section add a new entry for `node_modules/pact-consumer-js-dsl/dist/pact-consumer-js-dsl.js`.
1. Tell Karma about `pact-consumer-js-dsl.js` in `karma.conf.js`. In the `files: []` section add a new entry for `bower_components/pact-consumer-js-dsl/dist/web/pact-consumer-js-dsl.js`.

1. Allow tests to load resources from `pact` mock server. One way to do this is in the `karma.conf.js`, change `browsers: ['Chrome'],` or `browsers: ['PhantomJS'],` to,

Expand Down Expand Up @@ -104,19 +109,32 @@ This DSL relies on the Ruby [pact-mock_service][pact-mock-service] gem to provid

1. Let's run that bad boy!

* start the pact mock server with `bundle exec pact-mock-service -p 1234 -l log/pact.logs --pact-dir tmp/pacts`
* start the pact mock server with `pact-mock-service -p 1234 -l log/pact.logs --pact-dir tmp/pacts`
* run `karma start` (in another terminal window)
* inspect the pact file that has been written to "hello_consumer-hello_provider.json"

### Example
#### Web Example

Have a look at the [example](/example) folder. Ensure you have Google Chrome installed.
Have a look at the [example](/example/web) folder. Ensure you have Google Chrome installed.

$ cd example
$ bundle install
$ npm install
$ npm test


#### Nodejs Example

This is only an example on how to use the pact-consumer-js-dsl within Node. This is not best practice, but is a good starting point without creating a lengthy example using Grunt or Gulp with Protractor or Karma.

1. Start pact-mock-service with `pact-mock-service -p 1234 -l tmp/pact.log --pact-dir tmp/pacts`

1. Run nodejs command to setup pact consumer `node example/nodejs/setup.js`

1. Run your tests here with whatever you want, like Protractor for e2e testing

1. Run nodejs command to verify interactions and write pact files `node example/nodejs/teardown.js`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that there is only one big setup and one big tear down, and one big verify - is that what is happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bethesque that's the way the example does it, but it's not a requirement. I will need to expand more on this in the example. I just wanted to show something quick and dirty for using it in Node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Righto. If it works for you, that's great, but it's not the example I'd like to show people, because people will just unthinkingly copy stuff without critical thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt people would simply copy paste, plus, I was trying to go for the simplest example without having to setup a massive protractor project in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable. Maybe we can put in a comment to that effect?
Yeah, I was afraid there would be conflicts, sigh!


# Contributing

Please read [CONTRIBUTING.md](/CONTRIBUTING.md)
Expand Down
25 changes: 20 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{
"name": "pact-consumer-js-dsl",
"version": "0.1.0",
"version": "0.1.1",
"ignore": [
".gitignore",
".jshintrc",
".ruby-gemset",
".travis.yml",
"checkstyle.xml",
"gulpfile.js",
"node.prefix",
"node.suffix",
"package.json",
"src",
"spec"
],
"authors": [
"Fu Ying <fu.ying.er@rea-group.com>",
"Malinda Kapuruge <mkapuruge@dius.com.au>"
"Malinda Kapuruge <mkapuruge@dius.com.au>",
"Tarcio Saraiva <tsaraiva@dius.com.au>",
"Beth Skurrie <bskurrie@dius.com.au>",
"Michel Boudreau <michelboudreau@gmail.com>",
"Ben Sayers <bpsayers@gmail.com>"
],
"main": ["dist/pact-consumer-js-dsl.js"],
"dependencies": {
"jquery": "~1.8.3"
},
"dependencies": {},
"devDependencies": {}
}
Loading