google / truth

Fluent assertions for Java and Android
https://truth.dev/
Apache License 2.0
2.71k stars 258 forks source link

File Subject? #172

Open lukesandberg opened 9 years ago

lukesandberg commented 9 years ago

closure-templates has a bunch of tests for how the compiler generates files. It would be nice if Truth had some support for asserting on local files via File objects.

e.g. assertThat(file).exists() assertThat(file).doesNotExist() assertThat(file).contentEquals(otherFile); assertThat(file).isDirectory();

others? URL objects? java7 Paths?

kluever commented 9 years ago

Semi-related is (internal) bug 18722931 where I asked Colin to "polish up PathSubject and put it somewhere common".

sebhoss commented 9 years ago

+1 for the PathSubject. Currently the following does not compile due to method ambiguity:

    @Test
    public void shouldConvertToPath() throws IOException {
        // given
        final Path expectedPath = ...;

        // when
        final Path convertedPath = ...;

        // then
        ASSERT.that(convertedPath).isEqualTo(expectedPath);
    }

Declaring convertedPath as Object resolves the ambiguity. It's fine in this case since i'm treating convertedPath as an Object anyway, but having a specialized PathSubject sure would be nice!

jgustie commented 9 years ago

+1 on resolving the ambiguity; it took me a while to realize Path is an Iterable<Path> and a Comparable<Path>.

basil commented 8 years ago

+1, just hit the same issue.

cgruber commented 8 years ago

Hey @cgdecker - this would be a good thing. Let's sync about how I can help you get it moved in. I'd really like to see this in for 1.0.

cgdecker commented 8 years ago

To be honest, I've lost track of this and would have to dig up what I'd done again. I don't think it was ready or that we'd even worked out the API issues really. And I don't think I really have time to work on it this quarter. If you do want to try to push on getting this in, I can probably find what I had in terms of API plan and/or implementation and you can try to take it from there though.

alexkleiman commented 7 years ago

+1, I just hit this issue as well

dimo414 commented 7 years ago

See #285 for PathSubject; I'd like to see that added, even just as a stub.

nick-someone commented 5 years ago

PathSubject exists as part of the Truth8 extension now, mostly to resolve the ambiguity of IterableSubject and ComparableSubject: https://github.com/google/truth/blob/cf94032329283f44d0d91ee986bdfb9111298b2b/extensions/java8/src/main/java/com/google/common/truth/Truth8.java#L81

Leaving this open to decide how to do more assertions on the Path object.