acuminous / yadda Goto Github PK
View Code? Open in Web Editor NEWA BDD javascript library
A BDD javascript library
Pref javascript en coffeescript style, both single and multi-line
# Allow some description why a scenario is still @pending
// Or some extra info why a scenario is relevant, or ...
###
Blocks would allow for longer descriptive texts
###
/*
As would this one,
*/
# One could even include FIXME: provide reference to external specification
rk4n commented on f0eadb4
Guys, probably you can help me.
Host: Ubuntu 13.10.
CasperJS installed using http://docs.casperjs.org/en/latest/installation.html#installing-from-git .I'm getting an error:
/home/user/node_modules/yadda/examples/casper$ casperjs test.js
TypeError: 'undefined' is not an object (evaluating > 'require.cache['/home/user/node_modules/yadda/examples/casper/google-library.js']')
/home/user/node_modules/yadda/examples/casper/google-library.js:38But google-library.js contains only 37 lines.
Sorry you're having problems. I just tried yadda on Ubuntu 12.04 with casper latest stable and it runs OK. When I switch to latest from git I get
CasperError: can't find module async
/home/parallels/..../casperjs/bin/bootstrap.js:227 in patchRequire
My guess is they've changed the way require works, and the example has stopped working. I'll drop the casper guys a note and see if they can shed any light.
Hello
Ok
Fonctionnalité: xxxxx
@En attente
Scénario: task
Quand j'appelle l'adresse avec le token d'identification
BAD
Fonctionnalité: xxxxx
@En attente
Scénario: task
Quand j'appelle l'adresse avec le token d'identification
If i use space or tabulation for tags, yadda return
node_modules\yadda\lib\parsers\FeatureParser.js:72
throw new Error('Error parsing line ' + (index + 1) + ', "' + lin
^
Error: Error parsing line 11, " @En attente".
Text is unexpected at this time
Is'it a bug ?
Ami44
Hi,
I'm trying to execute provided example, but getting next error :
Error: Undefined Step: [Given 100 green bottles are standing on the wall]
at clear_winner (/home/igal/POC/Mocha/node_modules/yadda/lib/Competition.js:29:49)
at interpret_step (/home/igal/POC/Mocha/node_modules/yadda/lib/Interpreter.js:52:33)
at iterator (/home/igal/POC/Mocha/node_modules/yadda/lib/Interpreter.js:44:19)
at iterate (/home/igal/POC/Mocha/node_modules/yadda/lib/Array.js:69:13)
at Array.each_async (/home/igal/POC/Mocha/node_modules/yadda/lib/Array.js:75:9)
at Array.each_async (/home/igal/POC/Mocha/node_modules/yadda/lib/fn.js:24:23)
at interpret (/home/igal/POC/Mocha/node_modules/yadda/lib/Interpreter.js:39:21)
at yadda (/home/igal/POC/Mocha/node_modules/yadda/lib/Yadda.js:35:26)
at yadda (/home/igal/POC/Mocha/node_modules/yadda/lib/Yadda.js:34:84)
at /home/igal/POC/Mocha/bottles-test.js:10:11
at Context. (/home/igal/POC/Mocha/node_modules/yadda/lib/plugins/MochaPlugin.js:29:17)
at Test.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:194:15)
at Runner.runTest (/usr/lib/node_modules/mocha/lib/runner.js:358:10)
at /usr/lib/node_modules/mocha/lib/runner.js:404:12
at next (/usr/lib/node_modules/mocha/lib/runner.js:284:14)
at /usr/lib/node_modules/mocha/lib/runner.js:293:7
at next (/usr/lib/node_modules/mocha/lib/runner.js:237:23)
at Object._onImmediate (/usr/lib/node_modules/mocha/lib/runner.js:261:5)
at processImmediate as _immediateCallback
Any Idea why does it happen ?
thanks
Line 190 of LICENSE.txt file is not specified:
Copyright [yyyy] [name of copyright owner]
The other files do not recall the same license Apache License Version 2.0, January 2004` but another:
Copyright 2010 Acuminous Ltd / Energized Work Ltd
Is the Apache license applies to all files?
Ami44
Yadda should support data driven testing through example tables, e.g.
item | price | tax | qty | total
apple | 0.50 | N/A | 3 | 1.50
yogurt | 1.00 | 10% | 2 | 2.20
My preferred way to implement this would be with clever use of steps rather than through new code, e.g.
Given multiple line items:
item | price | tax | qty | total
apple | 0.50 | N/A | 3 | 1.50
yogurt | 1.00 | 10% | 2 | 2.20
Then each line item's total should be it's (price + tax) * quantity
.given('multiple line items', function(item, price, tax, quantity, total, done) {
lineItemExamples.push(new LineItem(item, price, tax, quantity, total));
done();
}
.then('each line item\'s total should be it\'s (price + tax) * quantity', function(done) {
_.each(lineItemExamples, function(example) {
assert.equal(lineItemService.get(example.item).total, example.total);
}
done();
})
I think this should work, but I've not tried it
Hi,
We use Gherkin to write scenarios throughout our organization. We are moving to Javascript and this tools seems promising. I tried using Yadda. So far it supports only Feature, Scenario, Give, When, Then and And keywords. It would be extremely useful if you provide full Gherkin support (like Background, Scenario Outline, Examples etc.). Are there are any plans?
When i write my features files, i often add readme.[md|rst] documentation.
but I must not forget to code var all_features = new Yadda.FileSearch('../features', /.*\.feature/).list();
Could var patterns = patterns || /.*/;
become var patterns = patterns || /.*\.feature/;
by default.
Thanks
Ami44
In real world, automation tests may have other features as dependencies. For instance, in order to test a shopping cart, I might need to first create a product catalog. To avoid duplication of steps, it would be helpful to reference other tests directly:
# A precondition to entire story
GivenFeature: path/to/precondition1.feature
Scenario: A scenario in which the user can run additional features as pre-requisites
# preconditions to scenario
GivenFeature: path/to/precondition2.feature,
Given ... // normal scenario steps
I can see this being a game changer for the already great Yadda.
I wanted to propose an idea and get your thoughts on it.
Annotations in feature files
Use case: When using Yadda with Selenium WebDriver, we may like to specify some annotations at the top of the file to state which browsers the particular feature file applies to. e.g. @browsers=Chrome,Firefox
Alternatively, maybe we could use the TextParser
to parse out 'Given' steps and decide which browser is applicable to run such a step (assuming a given of: Given I am on a Firefox browser
). - But this approach doesn't feel as clean.
The goal for us is to filter out tests designed to run on a particular browser and put them into 'buckets', that way, different machines can run different tests depending on what browsers are supposed to run.
What are your thoughts on this?
Hi,
I'm having lots of trouble formatting my features - I've followed the examples and can't see why there is an issue. Here's my example feature.
Feature: As a tech architect I want to list all my resources so that I can see what is live
Scenario: List types
Given I navigate to the homepage
Then I should see the resource
That's it. I get
> FAIL Error: A feature must contain one or more scenarios
I have the blank line I noticed in another reported issue. I have had these files working successfully with the mocha plugin, so I suspect this is is the FeatureParser issue. I assume I should be running them like this...
> casperjs test features/step_definitions/resource_overview_test.js
Also, it seems to dump a load of failed scenarios around bottles and google that makes unpicking the trace quite tricky at first - can I turn these off please?
Many thanks
Hi!
Is it possible to use Yadda together with one of the WebDriverJs bindings?
Creating a new yadda instance (var yadda = new Yadda(library, context)
) allows you to pass some sort of object which each step def can access via the this
keyword. Is there any technique you can think of utilising which would allow a change to the state object to be applied to all other step defs?
library.given("I do something", function(next) {
this.foo; //bar
this.foo = 'hello';
next();
});
The issue here is: in a new step def, this.foo
will still be equal to bar
when we actually wanted it to be equal to hello
.
It can be hard to debug what's going on during a failing test. It would help if I could see the steps that Yadda was executing. My preferred way to implement this is to fire an event on the following conditions...
Yadda: start, success, error
Interpreter: start, success, error
Macro: start, success, error
is it possible to write this with yadda ?:
Scenario:
Given a blog post named "Random" with:
"""
Some Title, Eh?
===============
Here is the first paragraph of my blog post.
Lorem ipsum dolor sit amet, consectetur adipiscing
elit.
"""
src :
Ami44
Is it possible to use this to perform async testing? If so can you provide an example where each step needs to perform an async action?
Hi!
When I try to setup Jasmine example
D:\yadda-master\examples\jasmine\spec>jasmine-node bottles-spec.js
I see this error:
Exception loading: D:\yadda-master\examples\jasmine\spec\bottles-spec.js
[TypeError: Cannot call method 'init' of undefined]
Could you explain, please, what I did wrong?
Hi! It seems that even though @pending has been documented as a way to mark a scenario as pending, for us it doesn't seem to have any effect. Is this a bug or am I maybe doing something wrong?
Feature: US-123
@Pending
Scenario: Implement something
Given user is on the result page
Then the page title should be ...
Then the header title should be ...
from the source code (MochaPlugin.js) it looks like you're mapping features to Mocha as follows:
Feature -> describe
Scenario -> it
Step (Unmapped)
This mapping causes a few problems:
Many other implementation I've seen before and one I created myself map steps to it
, to preserve Mocha's reporting.
Suggested mapping is:
Feature -> describe with 'Feature: ' prepended to feature summary text
Scenario -> describe with 'Scenario: ' prepended to scenario summary text
Step -> it with 'Given/When/Then ' prepended to step summary text
Prepending with the Guerkin keywords makes reports look consistent with feature definitions. So, instead of seeing:
Mocha Asynchronous Example
✓ A bottle falls from the wall
- Bottles are reset
1 passing (17ms)
1 pending
you'll see:
Feature: Mocha Asynchronous Example
Scenario: A bottle falls from the wall
✓ Given 100 green bottles are standing on the wall
✓ When 1 green bottle accidentally falls
✓ Then there are 99 green bottles standing on the wall
- Scenario: Bottles are reset
5 passing (17ms)
1 pending
and so with the proposed mapping, the following:
Feature: Example feature
As a very lazy programmer
I want to write some feature file
So that I can quickly make my mocha
Scenario: Reading the tests
Given I am in the test directory
When I read the index.js file
Then I should see "new Parser" somewhere
is expected to resolve to:
describe("Feature: Example feature", function() {
describe("As a very lazy programmer I want to write some feature file So that I can quickly make my mocha", function() {
describe("Scenario: Reading the tests", function() {
it("Given I am in the test directory", function() {
});
it("When I read the index.js file", function() {
});
it("Then I should see 'new Parser' somewhere", function() {
});
});
});
});
Here's a few more references that use the same mapping:
https://github.com/mklabs/mocha-gherkin
https://github.com/searls/jasmine-given
Could you please explain how to execute the yadda wrapped with jasmine ?
thanks
I should be possible to define a type (or converter) for a parameter. This will help avoid a common bug where strings should really be integers, but also help simply the code within the steps.
One approach would be to enhance the dictionary object, but it's proving quite difficult. I think I'm going to need to refactor how the steps are parsed and break them down into a tree of terms, values, patterns and expressions.
Yadda allows you to share context between steps, but the mocha plugin API doesn't support this.
hello @acuminous
I would like to run the example https://github.com/acuminous/yadda/tree/master/examples/casper but I do not.
package.json the file is missing, casper missing require and fs.read (filename) returns an error (fs.readFileSync (filename, 'utf8')).
What npm unit do you use to call casper?
Do you have an example that works for casperjs help me
sincerely
happy New Year
Ami44
Feature: Descriptive feature files
In order to communicate the added value of a feature and adhere to the cucumber style
As a feature document writer
I want to add some descriptive text to the feature heading without having to use comments
@example
Scenario: Feature file with descriptive text
Given this feature file
When run through the feature parser
It should skip the lines between the Feature line and the first line that has an annotation or scenario start
And it should not fail with a 'missing scenario' error
I've allowed test specific syntax to leak into the TextParser (the word 'Scenario'). I should have created a different parser class FeatureParser instead
see also https://github.com/acuminous/yadda#contexts-shared-state
Its a bit vague description, but as I understand it the context will be passed into the function's this object
// in the bottles-test.js
var context = {
foo: 'bar'
bar: function(number) { return new Wall(number) }
var yadda = new Yadda.yadda(library, context);
//
var library = new Library()
.given("$NUM green bottles are standing on the wall", function(number, next) {
this.foo.should.equal('bar')
wall this.bar(number) // would give me a new wall
next();
})
correct?
Hello
I have request which takes more than 2000ms.
Mocha fails because it's set to 2000ms and mocha --timeout 15000
seem has no effect
link : http://visionmedia.github.io/mocha/#suite-specific-timeouts
How set timeout or disable tiemout with yadda mocha plugin ?
Thank
Ami44
For setting up a common structure. Cucumber uses a Background that is run at the start of each scenario.
Would like to see named backgrounds, that I can specify in a scenario: Given background A, and perhaps also backgrounds referring another background (circular references may throw errors).
You mention that in the latest version there are breaking changes, but there is no documentation I can find around this. I know there are examples to look at in the repo, however they dont seem to work for me, I keep getting:
Error: TypeError: Cannot call method 'push' of undefined
at Suite.<anonymous> (C:\Code\Archive\Guff\node\express\test\node_modules\yadda\lib\plugins\MochaPlugin.js:28:23)
(See full trace by running task with --trace)
When following the examples, so are the examples up to date and if not could the documentation reflect this? If however they are up to date examples any ideas whats causing the issue above?
The code being used is:
var yadda = require("yadda").Yadda;
require("yadda").plugins.mocha();
var functions = require("./functions/example-functions");
var yaddaContainer = new yadda(functions);
yaddaContainer.mocha("Bottle Tests", "./tests/acceptance/features/example-test.feature");
I assume its the require("yadda").plugins.mocha() but dont know specifically what will be causing it.
The plugins are far less stable to the Yadda core, and I'd rather not keep republishing core because I want to release a new version of a plugin.
Yadda should provide a mechanism to execute multiple scenarios from a single test.
I propose changing the mocha library feature method accept
The FeatureFileFinder would look in some known locations place (e.g. anything below ./feature ./features, ./spec, ./specification) etc, for files matching a given pattern (e.g. *.feature, *.spec, *.specification)
If a user has a different naming convention Yadda should provide base classes for creating custom FeatureFileFinders
Node reports a warning when Yadda throws an exception. Yadda should detect whether it is running within a Node environment and throw an Error object instead.
Scenario: Simple Scenario
Given A
When B
Then C
Generate Error: Scenario requires one or more steps
.
Why require an empty line between Scenario and steps , users can forget.
It looks like using a step with a "+" in the step definition is causing an Undefined Step error.
For example, writing the feature file:
When I navigate to a music track page
Then I see a Google+ content panel
with the step definition:
library.then("Google+ links to content for sharing", function(next){
next()
});
causes the following error:
Uncaught Error: Undefined Step: [Then I see Google+ content for sharing]
Changing the wording from "Google+" to "Google Plus" fixes the issue, so it seems that the setup and logic elsewhere is correct.
Feature: missing steps
In order to help me getting started implementing the library
As a user of yadda
I want to have a quick summary of missing steps and the minimal code for implementation like cucumer
Scenario: 1 or more steps are not imlemented
Given a scenario
And some steps of the scenario have no matching definition in the used library
When running the test via mocha
Then I should get a quick overview of the missing steps
And per missing step a suggestion like '.given("$NUM green bottles are standing on the wall", function(number, next) { next(); /* Is there also a pending variant? */ })'
And no stack trace, as it has no meaning to see it failed in 'clear winner'
Hey,
Sorry to raise a new issue so quickly, but im a bit confused as to why my selector is always bringing back "undefined".
Here is the code:
var dictionary = new Dictionary()
.define('VERSION', /(\d.\d.\d.\d)|(\d.\d.\d)|(\d.\d)|(\d)/);
var library = new Library(dictionary)
.given("data at version $VERSION", function(version, next) {
console.log("VERSION: " + version);
data = dataFactory.GetDataForVersion(version);
next();
})
The regex seems right, and I was verifying it on rubular first
So are there any quirks around how I should be selecting variable content?
Hi,
I get this error:
[Error: Scenario requires one or more steps]
when I have do not leave a line inbetween Scenario and Given statements.
For example, I get the above error when I have scenario like this:
Scenario: Google Search
Given I am on the Google home page
Whereas, it works when I have it like this with a line space between Scenario and Given:
Scenario: Google Search
Given I am on the Google home page
Can you please help?
Libraries can only accept a single dictionary. I'd like to keep multiple dictionaries that I can compose into an uber dictionary and pass this to the library.
The following french feature file make parser fail:
Fonctionnalité: la page Linuxfr.org
Scénario: Ouverture de la page
étant donné un navigateur
quand on ouvre l'url http://linuxfr.org
alors la page d'accueil de Linuxfr s'ouvre
../../node_modules/mocha/bin/mocha --reporter spec page_test_fr.js
/home/poum/node_modules/yadda/lib/parsers/FeatureParser.js:127
if (!feature) throw new Error('A feature must contain one or more scen
^
Error: A feature must contain one or more scenarios
...
But this feature file is ok:
Fonctionnalité: la page Linuxfr.org
Scenario: Ouverture de la page
étant donné un navigateur
quand on ouvre l'url http://linuxfr.org
alors la page d'accueil de Linuxfr s'ouvre
Only "Scénario" is modified in "Scenario".
Same error with 'scénario', same success with 'scenario' ...
There is a problem with accented characters such as é
, à
, ç
...
If we add é
in examples examples/mocha-sync/features/bottles.feature
and examples/mocha-sync/bottles-library.js
(write wallé
instead of wall
) then mocha fail
Mocha Synchronous Example
? A bottle falls from the wall
1) No bottles are left
- Bottles are reset
2) 100 bottles are standing on a wall
3) 99 bottles are standing on a wall
4) 10 bottles are standing on a wall
? 4 of 6 tests failed:
1) Mocha Synchronous Example No bottles are left:
Error: Scenario cannot be interpreted
Given 1 green bottles are standing on the wall <-- Undefined Step
when 1 green bottle accidentally falls
then there are 0 green bottles standing on the wall
Hello
Is it possible to allow multiple translation for keyword Pending in localisation.
A bit like this: pending: '(: [Ee]n attendant|[Ee]n cours|[Tt]odo)'
Thank
Ami44
Yadda control flow is currently imperical - the Yadda class, runs the interpreter, which iterates over the steps and runs them. Yadda would be improved if control flow was triggered from events such as
yadda.start, yadda.stop, yadda.next, yadda.reset
interpreter.start, interprter.next, interpreter.step
etc.
The default implementation would automatically fire these events as steps and scenarios were completed, so no change would be apparent, but we could also substitute the default driver with alternative implementations enabling remote control from a UI similar to selenium's
Much nice than plain text files
I search an example with yadda + mocha + expressjs.
Is yadda users could share an example ?
Ami44
Feature: pending steps
In order to have a working library
As a feature library developer
I want to mark some steps as pending
Scenario: Making the test runnable with all steps pending
Given a feature file with scenarios and steps
and no time to develop the complete library required for it
and I create the step definitions in the library
and use next().pending or something like it as step definition
When I run the tests using eg mocha (or framework that supports pending tests)
Then the feature must be runnable
and not produce errors
and not produce failing tests
but scenarios should be marked as pending
Scenario: Making the test runnable with some steps pending
Given a feature file with scenarios and steps
and no time to develop the complete library required for it
and I create the step definitions in the library
and use next().pending or something like it as step definition for some steps
and next() for the other steps without any failing assertions
When I run the tests using eg mocha (or framework that supports pending tests)
Then the feature must be runnable
and not produce errors
and not produce failing tests
but scenarios having one or more steps marked pending should be marked as pending
and scenarios having no steps marked pending should be normally run and not marked pending
Currently hardcoded in the feature parser, would expect to have this as localisation as well
Hello. Been trying to write a json object out to file within a step so I can check the content is correct. Interestingly, I am unable to use fs.writeFile within the library file, as it is undefined.
i.e.
.then("I should see the resource $TYPES",function(type, next){
casper.then(function(){
var content = JSON.parse(this.getPageContent());
fs.writeFile('/tmp/t.json',content,function(err){
}) //fails (undefined)
//and
console.log(fs.writeFile) //undefined
expect(content).to.have.property("Reservations");
})
})
Do you have any idea what is causing the writeFile to be unbound (and others) i.e. readFile fails too..
Thanks
It's possible to get yadda and karma working together, but I have not settled on a clean way to accomplish this. Having the two working harmoniously together would be very valuable in my opinion. I've created a hack to show that it's possible: https://github.com/zpratt/yadda-karma-example
With exemple https://github.com/acuminous/yadda/tree/master/examples/mocha-async
.
I duplicate bottles.feature
to tests.feature
and duplicate bottles-library.js
to tests-library.js
How adapt test.js
to associate each *.feature
to *-library.js
I not found multiples features examples
Thank
Ami44
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.