Skip to content

Instantly share code, notes, and snippets.

@everzet
Created May 19, 2011 21:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save everzet/981759 to your computer and use it in GitHub Desktop.
Save everzet/981759 to your computer and use it in GitHub Desktop.
Why RSpec is not possible in PHP
<?php
/*
Why i think, that "RSpec is not possible in PHP"?
Cuz Ruby's syntax abilities can represent
natural language constructions:
object should equals 2
almost without changes in specs:
object.should == 2 || object.should equals(2)
but PHP: */
$this->spec($object)->should()->be(2);
/* does NOT!
And what's even worse - this construction
is far less readable, than more natural in
php assertions: */
$this->assertEquals(2, $object);
/* Why?
1. Cuz `->` is a READABLE noize in counterpart with non-readable `.`.
2. Cuz `$this->method(...)` is not a `method ...`
3. Cuz `$this->object` is not a `@object`
4. Cuz `$this->spec(...)` doesn't make sense at all in terms of behavior description.
It's again - readable noize
*/
@willdurand
Copy link

+1

@avalanche123
Copy link

something to consider:

<?php
$this->assert(2)->equals($object);
$this->assert($object)->is(2);

that could be a PHP way of Spec writing

Bottom line is copying syntax from another language should be done with a fair amount of thought, so that it actually simplifies use

@everzet
Copy link
Author

everzet commented May 19, 2011

@avalanche123 or:

<?php
$this->expect(2)->equals($object);
$this->expect($object)->is(2);

@avalanche123
Copy link

👏

@yuya-takeyama
Copy link

Hi, how do you think about this?
Its matchers are PHPSpec's.
https://github.com/yuya-takeyama/Speciphy

@dbernar1
Copy link

dbernar1 commented Jan 6, 2012

Yes, PHP's syntax sucks, but I don't see anything stopping you from implementing a pre-processor in PHP for syntax something like: https://gist.github.com/1569735 .

Otherwise, good point, see http://mechanicalrobotfish.com/posts/117-ruby-vs-php-bdd-beauty-contest-no-contest if you haven't already.

@dbernar1
Copy link

dbernar1 commented Jan 6, 2012

Though I do think that it would be easier to just teach Ruby to run PHP and to inspect PHP memory state.

@angelxmoreno
Copy link

lol, this is bananas. @dbernar1 "PHP's syntax" ? that syntax is not unique to PHP buddy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment